57 lines
1.1 KiB
Java
57 lines
1.1 KiB
Java
package com.inmind.object01;
|
||
|
||
//标准的javaBean
|
||
public class Car {
|
||
//属性
|
||
private String brand;
|
||
private double price;
|
||
private String color;
|
||
|
||
//alt+insert:快速自动生成构造方法,getset方法,等一系列代码(注意:功能Fn)
|
||
//构造方法
|
||
public Car() {//无参构造
|
||
}
|
||
|
||
public Car(String brand) {//有参构造
|
||
this.brand = brand;
|
||
}
|
||
|
||
public Car(String brand, double price, String color) {//满参构造
|
||
this.brand = brand;
|
||
this.price = price;
|
||
this.color = color;
|
||
}
|
||
|
||
//get/set方法
|
||
|
||
public String getColor() {
|
||
return color;
|
||
}
|
||
|
||
public void setColor(String color) {
|
||
this.color = color;
|
||
}
|
||
|
||
public String getBrand() {
|
||
return brand;
|
||
}
|
||
|
||
public void setBrand(String brand) {
|
||
this.brand = brand;
|
||
}
|
||
|
||
public double getPrice() {
|
||
return price;
|
||
}
|
||
|
||
public void setPrice(double price) {
|
||
this.price = price;
|
||
}
|
||
|
||
//上面的代码固定的,标准的javaBean,增加其他的一些成员方法
|
||
|
||
public void study() {
|
||
System.out.println(brand+price+color);
|
||
}
|
||
}
|