- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicMethodDispatch.java
More file actions
Latest commit
31 lines (28 loc) · 760 Bytes
/
Copy pathDynamicMethodDispatch.java
File metadata and controls
31 lines (28 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
classPhone{
publicvoidshowTime(){
System.out.println("Time is 8 am");
}
publicvoidon(){
System.out.println("Turning on Phone...");
}
}
classSmartPhoneextendsPhone{
publicvoidmusic(){
System.out.println("Playing music...");
}
publicvoidon(){
System.out.println("Turning on SmartPhone...");
}
}
publicclassDynamicMethodDispatch{
publicstaticvoidmain(String[] args) {
// Phone obj = new Phone();
Phoneobj = newSmartPhone(); // Yes it is allowed
// SmartPhone obj2 = new Phone(); // Not allowed
obj.showTime();
obj.on();
// obj.music(); Not Allowed
// SmartPhone sm = new SmartPhone();
// sm.music();
}
}