java 中的抽象类
代码实现
Telphone.java
package com.imooc;
public abstract class Telphone {
public abstract void call();
public abstract void message();
}
/javaDemo5/src/com/imooc/CellPhone.java
package com.imooc;
public class CellPhone extends Telphone {
public void call() {
// TODO Auto-generated method stub
System.out.println(“ 通过键盘来打电话 ”);
}
public void message() {
// TODO Auto-generated method stub
System.out.println(“ 通过键盘来打短信 ”);
}
}
SmartPhone.java
package com.imooc;
public class SmartPhone extends Telphone {
public void call() {
// TODO Auto-generated method stub
System.out.println(“ 通过语音来打电话 ”);
}
public void message() {
// TODO Auto-generated method stub
System.out.println(“ 通过语音来发短信 ”);
}
}
/javaDemo5/src/com/imooc/Initail.java
package com.imooc;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Telphone tel1 = new CellPhone();
tel1.call();
tel1.message();
Telphone tel2 = new SmartPhone();
tel2.call();
tel2.message();
}
}
运行