继承的概念:继承是从已有的类创建新类的过程。
继承过程
public class C {
public static void main(String args[]) {
Audi AudiA6=new Audi("Audi","40万",4,"A6");
}
}
class Car{
protected String name;
protected String price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public Car(String name, String price) {
super();
this.name = name;
this.price = price;
}
}
class Thecar extends Car{
protected int sta;
public int getSta() {
return sta;
}
public void setSta(int sta) {
this.sta = sta;
}
public Thecar(String name, String price, int sta) {
super(name, price);
this.sta = sta;
}
}
class Audi extends Thecar{
protected String models;
public Audi(String name, String price, int sta, String models) {
super(name, price, sta);
this.models = models;
System.out.println("车名:"+name+",价格:"+price+",厢数:"+sta+",车型:"+models);
}
}