
1、定义接口:
package test9_9photo;
public interface InterfaceTest {
String action="照相";
public void picture(String stype);
}
2、定义抽象类:
package test9_9photo;
public abstract class InterfaceTest_phone {
String phonestyle="手机";
public abstract void phoneofphoto(String stype);
public String toString(){
return "这是:"+phonestyle;
}
}
3、定义抽象类的子类手机的子类拍照类继承抽象类和接口:
package test9_9photo;
public class InterfaceTest_picturephone extends InterfaceTest_phone implements InterfaceTest {
public String picture="高像素小清新拍照手机";
public void takepicturetest() {
System.out.println("%%%%%%%%%%%%%%%%%");
System.out.println(" 类的InterfaceTest_picturephone的takepicture()方法中");
System.out.println("&&&&&&&&&&……………………&&&&&&&");
picture(action+"\n");
}
public void picture(String stype) {
System.out.println(" 这是:"+stype);
phoneofphoto(phonestyle+"子类的拍照手机!");
}
public void phoneofphoto(String stype) {
System.out.println("\n"+stype);
this.toString();
}
}
4、子类手机的子类拍照类的测试类写上main()方法,运行起来:
package test9_9photo;
public class InterfaceTest_picturephonemain {
public static void main(String[] args){
InterfaceTest_picturephone picturephone=new InterfaceTest_picturephone();
picturephone.takepicturetest();
picturephone.picture(picturephone.picture);
picturephone.picture(picturephone.phonestyle);
picturephone.phoneofphoto(picturephone.picture);
}
}
运算结果呢:
%%%%%%%%%%%%%%%%%
类的InterfaceTest_picturephone的takepicture()方法中
&&&&&&&&&&……………………&&&&&&&
这是:照相
手机子类的拍照手机!
这是:高像素小清新拍照手机
手机子类的拍照手机!
这是:手机
手机子类的拍照手机!
高像素小清新拍照手机
5、定义抽象类的另一个子类普通手机只继承抽象类手机类:
package test9_9photo;
public class InterfaceTest_usualphone extends InterfaceTest_phone{
String typeofphone="普通手机!";
public void phoneofphoto(String stype) {
System.out.println("这是:"+stype+"\n");
}
}
6、普通手机的测试类,然后写main()方法,进行具体实现调用测试功能:
package test9_9photo;
public class InterfaceTest_usualphonemain {
public static void main(String[] args) {
InterfaceTest_usualphone usual=new InterfaceTest_usualphone();
usual.phoneofphoto(usual.typeofphone);
}
}
7、测试运行结果:
这是:普通手机!