我是不是想太简单了?关于课后习题
//父类 Vehicle· package com.imooc; public class Vehicle { public void show(){ System.out.println("可以载多少人呢?"); } }
//子类 Taxi package com.imooc; public class Taxi extends Vehicle { public void show(){ String numb="1~4人"; String way="马路"; System.out.println("Taxi:"); System.out.println("一般可载:" + numb); System.out.println("工作媒介:" + way); } }
//子类 Bus package com.imooc; public class Bus extends Vehicle { public void show(){ String numb="1~50人"; String way="马路"; System.out.println("Bus:"); System.out.println("一般可载:" + numb); System.out.println("工作媒介:" + way); } }
//测试的Initial package com.imooc; public class Initial { public static void main(String[] args) { // TODO Auto-generated method stub Vehicle obj1 = new Taxi(); Vehicle obj2 = new Bus(); obj1.show(); obj2.show(); } }
子类Initial输出的结果为:
Taxi: 一般可载:1~4人 工作媒介:马路 Bus: 一般可载:1~50人 工作媒介:马路