/*
定义类,实现IPhone4中的两个功能
*/
class IPhone4
{
//定义打电话功能
public void call(){
System.out.println("拨号...发射");
}
//定义WIFI功能
public void WIFI(){
System.out.println("连接无线网");
}
}
/*
IPhone5上,沿袭4中的功能,扩展自己
*/
class IPhone5 extends IPhone4
{
//打电话,可以直接使用父类方法,但是5自己也具有这个方法,建立写这个方法
public void call(){
//父类已经做完了打电话,子类没有必要在做了,调用父类的call方法
super.call();
}
//扩展WIFI
public void WIFI(){
super.WIFI();
System.out.println("热点");
System.out.println("破密码");
}
}
/*
IHpone6上,沿袭5中的功能,扩展自己
*/
class IPhone6 extends IPhone5
{
public void call(){
super.call();
}
public void WIFI(){
super.WIFI();
System.out.println("抢网速");
}
}
class IPhoneTest
{
public static void main(String[] args)
{
IPhone4 i4 = new IPhone4();
i4.call();
i4.WIFI();
System.out.println("============");
IPhone5 i5 = new IPhone5();
i5.call();
i5.WIFI();
System.out.println("============");
IPhone6 i6 = new IPhone6();
i6.call();
i6.WIFI();
// System.out.println("Hello World!");
}
}
|
|