package project;
public class InitialCar {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car car=new Car();
car.num="冀6666";
car.name="奔驰";
car.money=4000000;
car.drive();
}
}
另一个代码:
package project;
public class Car extends AutoMobile {
//double money=3000000;
public void drive(){
System.out.println("奔驰代步");
}
public Car (){
System.out.println("name"+name+"money"+money+"Car类执行了");
}
public void qwe(){
System.out.println(super.money);
}
}
创建car对象时,执行car类的无参构造方法,此时name的值为空
//double money=3000000;
把“//”注释去掉