做出来了哈
父类 package com.demon; public class Traffic { public String name; public String way; public int num; public void method(){ } }
子类 package com.demon; public class Bus extends Traffic { public String name="巴士"; public String way="陆地"; public int num=40; public void method(){ System.out.println(name+"在"+way+"上行走,"+"可以载"+num+"个人"); } }
测试页面
package com.demon; public class Initail { public static void main(String[] args) { Traffic plane=new Plane(); plane.method(); Traffic bus=new Bus(); bus.method(); Traffic boat=new Boat(); boat.method(); } }