Java第四周常用类与集合框架之接口+抽象类9-9

这里写图片描述

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、测试运行结果:

这是:普通手机!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦思冥想行则将至

穷,有钱的大爷上个两分钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值