package b;
public class Car {
public final static Car pinpai=new Car();
public static Car instance()
{
return pinpai;
}
public void drive()
{
System.out.println("请安全驾驶!");
}
}
package b;
public class Aodi extends Car {
private String price;
private String xinghao;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public void biansu(int a)
{
if(a>0)
{
System.out.println("加速");
}
else if(a<0)
{
System.out.println("减速");
}
else
{
System.out.println("匀速前进");
}
}
}
package b;
public class Benchi extends Car {
private String price;
private String xinghao;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public void biansu(int a)
{
if(a>0)
{
System.out.println("加速");
}
else if(a<0)
{
System.out.println("减速");
}
else
{
System.out.println("匀速前进");
}
}
}
package b;
public class E {
public static void main(String[] args) {
Aodi aodi=new Aodi();
aodi.setXinghao("奥迪Q7");
aodi.setPrice("110万");
System.out.println(aodi.getXinghao());
System.out.println(aodi.getPrice());
aodi.biansu(90);
aodi.drive();
Benchi benchi=new Benchi();
benchi.setXinghao("迈巴赫");
benchi.setPrice("200万");
System.out.println(benchi.getXinghao());
System.out.println(benchi.getPrice());
benchi.biansu(-90);
benchi.drive();
}
}