-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP.java
More file actions
106 lines (78 loc) · 2.1 KB
/
OOP.java
File metadata and controls
106 lines (78 loc) · 2.1 KB
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
// Inheritance
// 1. Single lnheritance
import java.security.Principal;
import java.util.Scanner;
class animal{
void eat()
{
System.out.println("This Animal Can Eat...");
}
}
class Dog extends animal{
void sound()
{
System.out.println("Boww Boww Boww...");
}
public static void main(String[] args) {
Dog d1 = new Dog();
d1.eat();
d1.sound();
}
}
// 2. Multilevel Inheritance
class a {
int one = 1;
}
class b extends a {
int two = 2;
}
class c extends b {
int three = 3;
public static void main(String[] args) {
c obj1 = new c();
System.out.println(obj1.one);
System.out.println(obj1.two);
System.out.println(obj1.three);
}
}
// 3. Hieracihal Inheritance
class school{
void sports()
{
System.out.println("Congarts you been Selected to Football Team");
System.out.println();
}
void sports_Sir()
{
System.out.println("Dear Sir! You Been Appoined to sports Coach congarts");
}
}
class student extends school{
void classA()
{
System.out.println("10 Students are selecte to Criket ");
System.out.println();
}
void classB()
{
System.out.println("10 Students are selecte to Football");
System.out.println();
}
public static void main(String[] args) {
student s1 = new student();
s1.classA();
s1.classB();
s1.sports();
}
}
class teacher extends school{
void principal()
{
System.out.println("Congrats sir! you're appointed to Principal ");
}
public static void main(String[] args) {
teacher t1 = new teacher();
t1.sports_Sir();
t1.principal();
}
}