-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path22_Polymorphism
60 lines (55 loc) · 1.58 KB
/
22_Polymorphism
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.company;
interface MyCamera{
void takeSnap();
void recordVideo();
private void greet(){
System.out.println("Good Morning");
}
default void record4KVideo(){
greet();
System.out.println("Recording in 4k...");
}
}
interface MyWifi{
String[] getNetworks();
void connectToNetwork(String network);
}
class MyCellPhone{
void callNumber(int phoneNumber){
System.out.println("Calling "+ phoneNumber);
}
void pickCall(){
System.out.println("Connecting... ");
}
}
class MySmartPhone extends MyCellPhone implements MyWifi, MyCamera{
public void takeSnap(){
System.out.println("Taking snap");
}
public void recordVideo(){
System.out.println("Taking snap");
}
// public void record4KVideo(){
// System.out.println("Taking snap and recoding in 4k");
// }
public void GPS(){
System.out.println("GPS");
}
public String[] getNetworks(){
System.out.println("Getting List of Networks");
String[] networkList = {"Harry", "Prashanth", "Anjali5G"};
return networkList;
}
public void connectToNetwork(String network){
System.out.println("Connecting to " + network);
}
}
public class Polymorphism {
public static void main(String[] args) {
MyCamera cam1 = new MySmartPhone(); // It can only access the functions in MyCamera
cam1.record4KVideo();
// cam1.getNetworks; // Not Allowed due to polymorphism
MySmartPhone msp = new MySmartPhone();
msp.GPS();
}
}