 
		慕尼黑9214616
2017-06-20 17:25
//父类
public class Vehicle {
	public int carryNum;//可载人数
	public String move;//运行方式
    public String models;//工具类型
   public void method(){
	   System.out.println("交通工具中:"+models+"在"+move+"可以载客"+carryNum+"人");
   }
}
//公交车子类
public class Bus extends Vehicle {
	public void method(){
		   this.carryNum=40;
		   this.move="陆地";
		   this.models="公交车";
	   System.out.println("交通工具中:"+models+"在"+move+"可以载客"+carryNum+"人");
	   }
}
//飞机子类
public class Plane extends Vehicle{
	public void method(){
		   this.carryNum=200;
		   this.move="天空";
		   this.models="飞机";
	   System.out.println("交通工具中:"+models+"在"+move+"可以载客"+carryNum+"人");
	   }
}
//轮船子类
public class Ship extends Vehicle {
   public void method(){
	   this.carryNum=2000;
	   this.move="海洋";
	   this.models="轮船";
   System.out.println("交通工具中:"+models+"在"+move+"可以载客"+carryNum+"人");
   }
}
//测试
public class Test {
	public static void main(String[] args) {
	Vehicle d = new Vehicle();
	Vehicle d1= new Bus();
	Vehicle d2= new Ship();
	Vehicle d3= new Plane();
    d1.method();
    d2.method();
    d3.method();
	}
}
 
				去看看我的那个提问,你这个写法跟我写的一样,太繁琐,而且根本没有体现出继承!
 
				也是继承
Java入门第二季
531291 学习 · 6327 问题
相似问题