努力敲代码的图图 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 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存