java不支持多继承
可以采用这两种方式实现多继承的效果
1 【对象组合】 2 【成员内部类继承】
class Call { public void callSomebody(String phoneNum) { System.out.println("我在打电话喔,呼叫的号码是:" + phoneNum); } }
class SendMessage { public void sendToSomebody(String phoneNum) { System.out.println("我在发短信喔,发送给 :" + phoneNum); } }
public class Phone { private class MyCall extends Call {} private class MySendMessage extends SendMessage {} private MyCall call = new MyCall(); private MySendMessage send = new MySendMessage(); public void phoneCall(String phoneNum) { call.callSomebody(phoneNum); } public void phoneSend(String phoneNum) { send.sendToSomebody(phoneNum); } public static void main(String[] args) { Phone phone = new Phone(); phone.phoneCall("110"); phone.phoneSend("119"); } }