努力敲代码的图图 2022-10-07 16:19 采纳率: 75%
浏览 33
已结题

关于#抽象类#和接口的问题,如何解决?

有同学能帮我看一下我写的有啥问题嘛

题目:利用抽象类和接口知识点编写一个功能

例如 手机 >非智能手机>智能手机

   抽象类的基本属性            手机的基本属性

  抽象类的抽象方法    基本电话功能

接口

         1,有摄像和拍照功能

          2,蓝牙功能

          3,定位功能

代码:package com.dmd;

public abstract class phone {
private String brand;
private int price;

public abstract void call();

public abstract void message();

public phone(String brand, int price) {
    System.out.println("Basic attributes and functions");
    this.brand = brand;
    this.price = price;
    this.call();
    this.message();
}

public interface photograph {
    public void photograph();
}

public interface bluetooth {
    public void bluetooth();
}

public interface location {
    public void location();
}

}

  • 写回答

1条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-10-07 19:35
    关注
    public abstract class phone {
        private String brand;
        private int price;
    
        public String getBrand() {
            return brand;
        }
    
        public void setBrand(String brand) {
            this.brand = brand;
        }
    
        public int getPrice() {
            return price;
        }
    
        public void setPrice(int price) {
            this.price = price;
        }
    
        public abstract void call();
        public abstract void message();
    
    }
    
    
    
    
    public interface phoneInterface {
        public void photograph();
        public void bluetooth();
        public void location();
    
    }
    
    public class zhinengPhone extends phone implements phoneInterface {
        @Override
        public void call() {
            System.out.println(this.getBrand()+"打电话功能");
        }
    
        @Override
        public void message() {
            System.out.println(this.getBrand()+"发短信功能");
        }
    
        @Override
        public void photograph() {
            System.out.println(this.getBrand()+"拍照功能");
        }
    
        @Override
        public void bluetooth() {
            System.out.println(this.getBrand()+"蓝牙功能");
    
        }
    
        @Override
        public void location() {
            System.out.println(this.getBrand()+"定位功能");
    
        }
    
        public static void main(String[] args) {
            zhinengPhone zhinengPhone=new zhinengPhone();
            zhinengPhone.setBrand("华为");
            zhinengPhone.setPrice(8888);
            zhinengPhone.call();
            zhinengPhone.message();
            zhinengPhone.photograph();
            zhinengPhone.location();
            zhinengPhone.bluetooth();
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月15日
  • 已采纳回答 10月7日
  • 创建了问题 10月7日

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀