手机

手机类

package cn.phone;

public class Phone {
        private String brand;
        private String type;
        public void sendInfo() {
            System.out.println("发信息的功能");
        }
        public void call() {
            System.out.println("通电话的功能");
        }
        
        public String getBrand() {
            return brand;
        }
        public void setBrand(String brand) {
            this.brand = brand;
        }
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        public  void print() {
            System.out.println("这是一部"+this.brand+this.getType()+"手机");
        }
}

接口类

package cn.phone;
//照相接口
public interface TheakePictures {
    public void takePictures() ;
}
package cn.phone;
//l连接网络接口
public interface Network {
    public void networkConn();
}
package cn.phone;
//播放接口
public interface PlayWiring {
    public void play();
}

智能手机类

package cn.phone;

public class AptitudePhone extends Phone implements TheakePictures,Network,PlayWiring{
    public void takePictures() {
        System.out.println("照相功能");
    }
    public void networkConn() {
        System.out.println("连接网络功能");
    }
    public void play() {
        System.out.println("播放功能");
    }
//    public void print() {
//        
//        System.out.println();
//    }
    
    public void toprint() {
        super.call();
        super.sendInfo();
        takePictures();
        networkConn();
        play();
    }
}

普通手机类

package cn.phone;

public class CommonPhone extends Phone implements PlayWiring {
    public void play() {
        System.out.println("播放功能");
    }
    public void toprint() {
        super.call();
        super.sendInfo();
        play();
        
    }
}

测试类

package cn.phone;

public class Test {
    public static void main(String[] args) {
        Phone phone = new Phone();
        AptitudePhone aptitudePhone = new AptitudePhone();
        aptitudePhone.setBrand("苹果");
        aptitudePhone.setType("xr");
        aptitudePhone.print();
        aptitudePhone.toprint();
        CommonPhone commonPhone = new CommonPhone();
        commonPhone.setBrand("VIVO");
        commonPhone.setType("X9");
        commonPhone.print();
        commonPhone.toprint();
    }
}

原文地址:https://www.cnblogs.com/lev1/p/11218815.html