问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

java 初学者 遇到了一道题没有头绪 请大侠们帮忙解答 谢谢。。。。

发布网友 发布时间:2022-05-25 17:33

我来回答

4个回答

热心网友 时间:2023-11-25 06:06

总共7个类
package Mobile;

public interface Camera {
public void takePhoto();
}

package Mobile;

public interface MobilePhone {

public void call();
public void receive();
public void sendMsg();
public void receiveMsg();

}

package Mobile;

public interface CameraPhone extends MobilePhone, Camera {

}

package Mobile.Impl;

import Mobile.CameraPhone;

public class MotoPhone implements CameraPhone {

public void call() {
System.out.println("Moto call");

}

public void receive() {
System.out.println("Moto println");

}

public void receiveMsg() {
System.out.println("Moto receiveMsg");

}

public void sendMsg() {
System.out.println("Moto sendMsg");

}

public void takePhoto() {
System.out.println("Moto takePhoto");

}

}

package Mobile.Impl;

import Mobile.CameraPhone;

public class NokiaPhone implements CameraPhone {

public void call() {
System.out.println("Nokia call");

}

public void receive() {
System.out.println("Nokia receive");

}

public void receiveMsg() {
System.out.println("Nokia receiveMsg");

}

public void sendMsg() {
System.out.println("Nokia sendMsg");

}

public void takePhoto() {
System.out.println("Nokia takePhoto");

}

}

package Student;

import Mobile.CameraPhone;
/*
* 学生类
* 定义 姓名 手机使用型号
*
* */
public class Student {

public String name ; // 学生姓名

public CameraPhone cPhone ; // 学生手机

public CameraPhone getCPhone() {
return cPhone;
}

public void setCPhone(CameraPhone phone) {
cPhone = phone;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

/*
* 带参数的构造方法
*
* */
public Student(String name , CameraPhone cPhone ){

this.setName(name); // 初始化参数
this.setCPhone(cPhone); // 初始化参数
}

/*
* 拨打电话功能
* */
public void call(){
this.cPhone.call();

}

}

测试类
import Mobile.Impl.MotoPhone;
import Mobile.Impl.NokiaPhone;
import Student.Student;

public class TestInterface {

/**
* @param args
*/
public static void main(String[] args) {
NokiaPhone nokie = new NokiaPhone();
MotoPhone moto = new MotoPhone();
Student student = new Student("张三" , nokie);
student.call();
Student student1= new Student("李四" , moto);
student1.call();

}

}

热心网友 时间:2023-11-25 06:07

package test;

public class TestInterface {

/**
* @param args
*/
public static void main(String[] args) {
Student s1 = new Student("张三",new NokiaPhone());
Student s2 = new Student("李四",new MotoPhone());
s1.myCall();
s2.myCall();
}
}

interface MobilePhone{
void call();
void receive();
void sendMsg();
void receiveMsg();
}
interface Camera{
void takePhoto();
}
interface CameraPhone extends MobilePhone,Camera{
}
class NokiaPhone implements CameraPhone{
@Override
public void call() {
System.out.print("Nokia call");
}
@Override
public void receive() {
System.out.print("Nokia receive");
}
@Override
public void receiveMsg() {
System.out.print("Nokia receiveMsg");
}
@Override
public void sendMsg() {
System.out.print("Nokia sendMsg");
}
@Override
public void takePhoto() {
System.out.print("Nokia takePhoto");
}
}
class MotoPhone implements CameraPhone{
@Override
public void call() {
System.out.print("Moto call");
}
@Override
public void receive() {
System.out.print("Moto receive");
}
@Override
public void receiveMsg() {
System.out.print("Moto receiveMsg");
}
@Override
public void sendMsg() {
System.out.print("Moto sendMsg");
}
@Override
public void takePhoto() {
System.out.print("Moto takePhoto");
}
}

class Student{
private String name;
private CameraPhone myPhone;
public Student(String name,CameraPhone phone){
this.name=name;
this.myPhone=phone;
}
public void myCall(){
this.myPhone.call();
}
}

热心网友 时间:2023-11-25 06:07

public interface MobilePhone {
public void call();
public void receive();
public void sendMsg();
public void receiveMsg();
}

public interface Camera {
public void takePhoto();
}

public class CameraPhone implements MobilePhone, Camera {

@Override
public void call() {
// TODO Auto-generated method stub
System.out.println("call() is called!");
}

@Override
public void receive() {
// TODO Auto-generated method stub
System.out.println("receive() is called!");
}

@Override
public void receiveMsg() {
// TODO Auto-generated method stub
System.out.println("receiveMsg() is called!");
}

@Override
public void sendMsg() {
// TODO Auto-generated method stub
System.out.println("sendMsg() is called!");
}

@Override
public void takePhoto() {
// TODO Auto-generated method stub
System.out.println("takePhoto() is called!");
}

}

public class MotoPhone extends CameraPhone {
@Override
public void call() {
// TODO Auto-generated method stub
System.out.println("MotoPhone call() is called!");
}

@Override
public void receive() {
// TODO Auto-generated method stub
System.out.println("MotoPhone receive() is called!");
}

@Override
public void receiveMsg() {
// TODO Auto-generated method stub
System.out.println("MotoPhone receiveMsg() is called!");
}

@Override
public void sendMsg() {
// TODO Auto-generated method stub
System.out.println("MotoPhone sendMsg() is called!");
}

@Override
public void takePhoto() {
// TODO Auto-generated method stub
System.out.println("MotoPhone takePhoto() is called!");
}
}

public class NokiaPhone extends CameraPhone {
@Override
public void call() {
// TODO Auto-generated method stub
System.out.println("NokiaPhone call() is called!");
}

@Override
public void receive() {
// TODO Auto-generated method stub
System.out.println("NokiaPhone receive() is called!");
}

@Override
public void receiveMsg() {
// TODO Auto-generated method stub
System.out.println("NokiaPhone receiveMsg() is called!");
}

@Override
public void sendMsg() {
// TODO Auto-generated method stub
System.out.println("NokiaPhone sendMsg() is called!");
}

@Override
public void takePhoto() {
// TODO Auto-generated method stub
System.out.println("NokiaPhone takePhoto() is called!");
}
}

public class Student {
private String name;
private CameraPhone myPhone;

public Student(String name,CameraPhone myPhone){
this.name=name;
this.myPhone=myPhone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CameraPhone getPhone() {
return myPhone;
}
public void setPhone(CameraPhone myPhone) {
this.myPhone = myPhone;
}

public void myCall(){
this.myPhone.call();
}
}

public class TestInterface {
public static void main(String args[]){
NokiaPhone Nokia=new NokiaPhone();
MotoPhone Moto=new MotoPhone();
Student stu1=new Student("张三",Nokia);
Student stu2=new Student("李四",Moto);
stu1.myCall();
stu2.myCall();
}
}

热心网友 时间:2023-11-25 06:08

interface MobilePhone{
void call();
void receive();
void sendMsg();
void receiveMsg();
}
interface Camera{
void takePhoto();
}
........。。。。
其他的就是这么定义的,要继承该接口要全部实现其方法追问嗯 前面的我会写后面几条就混乱了是不是得用上向上转型呀。。。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
找专业防水队做完还漏水怎么维权 法院会受理房屋漏水造成的纠纷吗? 巴西龟最长活多久,家养!!! 养胃的药最好的是什么啊 婴儿积食发烧不愿吃药怎么办 板门穴位在哪个部位 手机设置放偷看的方法? 凝结水回收器生产厂家? 个人账户养老金预测公式:现有5万元,缴费20年,能领多少钱? 临沂比较有名的男装品牌 1、 编写一个Java程序,程序中有一个类Telephone, Telephone类中包含有电话品牌、 超导暖风多功能led浴霸线路安装图 编码创建一个手机类Phones,定义打电话方法call(). 创建两个子类 请问中国国际航空客服是多少? java问题, 急求 绿能超导浴霸接线视频 需要你们的帮助 定义一个手机类Phone,要求如下: Java定义一个描述电话的类,至少描述电话类的两种属性和一种功能? led浴霸三和一怎么接线 中国国际航空客服电话 “Home”键在哪? 电脑上用的2.0音箱那款音质最好阿?再次强调要音质好的,要高保真立体声的?谢谢,。。 想买个2.0音箱,求高手推荐款,时尚的点音箱也行? 大家推荐一下哪个牌子的2.0音箱好 七龙珠卡卡罗特技能咋蓄力 龙珠Z卡卡罗特打开显示器黑屏 龙珠z卡卡罗特怎么打开背包 2.0音箱哪个好 龙珠卡卡罗特怎么打出地球 2.0音箱什么牌子的好啊? Java以电话Phone为父类 请问,浴霸怎么接线 一个java接口的问题~~ mp是怎么材料 肘子浇汁的汁怎么做 不锈钢管件MP是什么意思? 塑料中mp料是什么意思 15MnV是什么材料 符合ASTM-A-159标准里面的G3500级材料是什么牌号铸铁 洗衣机龙头什么牌子好j,d 您好,我昨天买了一台海尔XQB50-728E 洗衣机,可是我家的水龙头老是漏水,我想问下用什么样的水龙头好? 电脑做了系统打电子面单还要安装什么吗 大学里 室内设计属于什么专业? 美术生的 室内设计理科生可不可以报,属于哪个专业 什么叫智能辅助 智能辅助系统真的有用吗?还是厂商炒作的噱头 经传软件的智能辅助是不是非常强?这个指标干啥的?每次说遇到辅助线都要注意风险,好几次都跌下去了 智能辅助线破位是什么 智能客服助理是什么?为什么未来客服一定会用到智能客服辅助系统? 一般封多久就自动解封?