forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritanceExample1.java
More file actions
48 lines (36 loc) · 1002 Bytes
/
InheritanceExample1.java
File metadata and controls
48 lines (36 loc) · 1002 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
37
38
39
40
41
42
43
44
45
46
47
48
package InfinityJune21.OOPS.Inheritance;
class A {
int i, j;
void showij() {
System.out.println("Values of i and j are: " + i + " " + j);
}
}
class B extends A {
int k;
void showk() {
System.out.println("Values of k: " + k);
}
void sum() {
System.out.println("Sum of i, j, and k is: " + (i + j + k));
}
}
public class InheritanceExample1 {
public static void main(String[] args) {
A superOb = new A();
B subOb = new B();
superOb.i = 10;
superOb.j = 20;
System.out.println("Contents of superOb: ");
superOb.showij();
System.out.println();
subOb.i = 70;
subOb.j = 80;
subOb.k = 90;
System.out.println("Contents of subOb: ");
subOb.showij();
subOb.showk();
System.out.println();
subOb.sum();
System.out.println("Value of i in superOb: " + superOb.i);
}
}