Skip to content

Commit dc9f94e

Browse files
authored
Add files via upload
1 parent 649a1dc commit dc9f94e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Methods/MethodOverriding3.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class A {
2+
int i, j;
3+
4+
A() {
5+
6+
}
7+
8+
A(int a, int b) {
9+
i = a;
10+
j = b;
11+
}
12+
13+
void Showij() {
14+
System.out.println("A's i=" + i);
15+
System.out.println("A's j=" + j);
16+
}
17+
}
18+
19+
class B extends A {
20+
int k;
21+
22+
B(int a, int b, int c) {
23+
i = a;
24+
j = b;
25+
k = c;
26+
}
27+
28+
void Showij() {
29+
super.Showij();
30+
System.out.println("B's i=" + i);
31+
System.out.println("B's j=" + j);
32+
33+
}
34+
35+
void Showk() {
36+
System.out.println("k=" + k);
37+
}
38+
}
39+
40+
/**
41+
* SingleInheritence
42+
*/
43+
class MethodOverriding3 {
44+
public static void main(String[] args) {
45+
A obj1 = new B(12, 45, 78);
46+
obj1.Showij();
47+
B subobj = new B(5, 10, 15);
48+
subobj.Showk();
49+
}
50+
}

0 commit comments

Comments
 (0)