-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicmethodDispatch.java
More file actions
35 lines (29 loc) · 991 Bytes
/
DynamicmethodDispatch.java
File metadata and controls
35 lines (29 loc) · 991 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
32
33
34
35
//Implementing Dynamic Dispatch Method or Run time Polymorphism
//Help us to call that particular function using 2nd class object like we can call override
//function by taking reference of the parent class
//but will help to access all the function of parent class but we can only call
class Phone{
public void ShowDay() {
System.out.println("ASK TO ANYONE....");
}
public void on() {
System.out.println("TURNING ON PHONE.....");
}
}
class Smartphone extends Phone {
public void music() {
System.out.println("Turning on Spotify.... ");
}
public void on() {
System.out.println("Turning on your Smartphone....");
}
}
public class DynamicmethodDispatch {//Run time Polymorphism
public static void main(String[] args) {
//Now creating object for Dynamic method Dispatch
Phone Apple=new Smartphone();
Apple.ShowDay();//Can call All the the functions of phone
Apple.on();
//Apple.music();//Cannot call not overriding
}
}