-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathProgram_13.java
More file actions
36 lines (31 loc) · 914 Bytes
/
Program_13.java
File metadata and controls
36 lines (31 loc) · 914 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
36
// program showing Hierarchical Inheritance
// creating the base class(or superclass)
class BaseClass{
int parentNum = 10;
void display(){
System.out.println("\nThis is BaseClass.\n");
}
}
// creating the subclass1 that inherits the base class
class SubClass1 extends BaseClass{
int num1 = 1;
void callBaseClass(){
display();
}
}
// creating the subclass2 that inherits the base class
class SubClass2 extends BaseClass{
int num2 = 2;
void callBaseClass(){
display();
}
}
public class Practical_13{
public static void main(String args[]){
SubClass1 cob1 = new SubClass1 ();
SubClass2 cob2 = new SubClass2 ();
cob1.callBaseClass();
System.out.println("parentNum * childNum1 = " + cob1.parentNum * cob1.num1);
System.out.println("parentNum * childNum2 = " + cob2.parentNum * cob2.num2);
}
}