We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent afa5314 commit 0ee2506Copy full SHA for 0ee2506
49.Dynamic_Method_Dispatch/cwh_49_dynamic_method_dispatch.java
@@ -0,0 +1,31 @@
1
+class Phone {
2
+ public void showTime() {
3
+ System.out.println("Time is 8 am");
4
+ }
5
+ public void on() {
6
+ System.out.println("Turning on Phone...");
7
8
+}
9
+
10
+class SmartPhone extends Phone {
11
+ public void music() {
12
+ System.out.println("Playing music...");
13
14
15
+ System.out.println("Turning on SmartPhone...");
16
17
18
+public class cwh_49_dynamic_method_dispatch {
19
+ public static void main(String[] args) {
20
+ // Phone obj = new Phone(); // Allowed
21
+ // SmartPhone smobj = new SmartPhone(); // Allowed
22
+ // obj.name();
23
24
+ Phone obj = new SmartPhone(); // Yes it is allowed
25
+ // SmartPhone obj2 = new Phone(); // Not allowed
26
27
+ obj.showTime();
28
+ obj.on();
29
+ // obj.music(); Not Allowed
30
31
0 commit comments