forked from Saikat2407/DSA_Hacktoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_oops.java
106 lines (53 loc) · 1.21 KB
/
all_oops.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class One {
public void display() {
System.out.println("One");
}
}
//inheritance
class Two extends One {
@Override
public void display() {
System.out.println("Two");
}
public int add(int x, int y) {
return x+y;
}
//Overload
public double add(double x,double y) {
return x+y;
}
}
//encapsulation example
class EncapTest {
private String name;
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
}
//abstraction
abstract class TwoWheeler {
public abstract void run();
}
class Honda extends TwoWheeler{
public void run(){
System.out.println("\nbike is Running..");
}
}
class all_oops {
public static void main(String[] args) {
One a=new One();
a.display();
Two b=new Two();
b.display();
System.out.println(b.add(4,2));
System.out.println(b.add(5.,2.)); //polymorphism
EncapTest encap = new EncapTest();
encap.setName("Sandeep's");
System.out.print("Name : " + encap.getName() );
TwoWheeler test = new Honda();
test.run();
}
}