父类car:车的奔跑速度,类型,颜色
子类Kache:复写父类中的三个方法
子类Moto:复写父类中的三个方法
测试类Test1:分别输出车的速度,类型,颜色
实现源代码:
//父类
package Acm.day01;
public class Car {
public void Run(){
System.out.println("极速");
}
public void Style(){
System.out.println("越野");
}
public void Color(){
System.out.println("白色");
}
}
//Kache类
package Acm.day01;
public class Kache extends Car {
@Override
public void Run() {
// TODO Auto-generated method stub
//super.Run();
System.out.println("高速");
}
@Override
public void Style() {
// TODO Auto-generated method stub
//super.Style();
System.out.println("这是一辆卡车");
}
@Override
public void Color() {
// TODO Auto-generated method stub
//super.Color();
System.out.println("红色");
}
public Kache() {
super();
// TODO Auto-generated constructor stub
}
}
//Moto类
package Acm.day01;
public class Moto extends Car {
@Override
public void Run() {
// TODO Auto-generated method stub
super.Run();
}
@Override
public void Style() {
// TODO Auto-generated method stub
super.Style();
}
@Override
public void Color() {
// TODO Auto-generated method stub
super.Color();
}
public Moto() {
// TODO Auto-generated constructor stub
}
}
//测试类
package Acm.day01;
public class Test1 {
public static void main(String[] args){
Kache kache = new Kache();
System.out.print("车的类型是:");
kache.Style();
System.out.print("车的奔跑速度是:");
kache.Run();
System.out.print("车的颜色是:");
kache.Color();
System.out.println();
Moto moto = new Moto();
System.out.print("车的类型是:");
moto.Style();
System.out.print("车的奔跑速度是:");
moto.Run();
System.out.print("车的颜色是:");
moto.Color();
}
}