-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance1.java
More file actions
112 lines (92 loc) · 2.11 KB
/
Inheritance1.java
File metadata and controls
112 lines (92 loc) · 2.11 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
107
108
109
110
111
112
// Inheritance
// class Human // Parent/Super class...(extends object)
// {
// int age;
// private String name;
// Human()
// {
// System.out.println("This is a constructor");
// }
// void sleep()
// {
// age = 19;
// System.out.println("Humans are the worst creatures!!");
// System.out.println(age);
// }
// }
// class Teacher extends Human // Child/Sub class...
// {
// int experience;
// void teach()
// {
// experience = 23;
// System.out.println("You are an experienced teacher!!");
// System.out.println(experience);
// }
// }
// class Student extends Teacher // Child/Sub class...
// {
// void display()
// {
// System.out.println("Your age is : " + age);
// // System.out.println("Your name is : " + name); // private members are not inherited...
// }
// }
// class Joker //extends object (by default)
// {
// int jok;
// void disp()
// {
// System.out.println(jok);
// }
// }
//_____________________________________________________________________________________________
class Aeroplane
{
void takeOff()
{
System.out.println("Plane is taking off!!");
}
void fly()
{
System.out.println("Plane is flying!!");
}
}
class CargoPlane extends Aeroplane
{
// void takeOff() // Inherited method
// {
// System.out.println("Plane is taking off!!");
// }
void fly() // Overhidden method
{
System.out.println("Plane is flying cargo!!");
}
void type() // Specialized method
{
System.out.println("Metal Plane!!");
}
}
class PassengerPlane extends Aeroplane
{
void fly() // Overhidden method
{
System.out.println("Plane is flying Passengers!!");
}
}
class Inheritance1
{
public static void main(String []args)
{
// Student st = new Student();
// st.sleep();
// st.teach();
// st.display();
CargoPlane cp = new CargoPlane();
cp.fly();
cp.takeOff();
PassengerPlane pp = new PassengerPlane();
pp.fly();
pp.takeOff();
}
}