-
类和对象是:
类:是共同特征的描述(设计图);
对象:是真实存在的具体实例。
public class Car {
//属性(成员变量)
String name;
double price;
//行为(方法)
public void start(){
System.out.println(name + "价格是:" + price + "启动了");
}
public void run(){
System.out.println(name + "价格是:" + price + "跑得很快");
}
}
public class Test {
public static void main(String[] args) {
Car c = new Car();
c.name = "奔驰";
c.price = 32.12432;
System.out.println(c.name);
System.out.println(c.price);
c.start();
c.run();
}
}