-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOverride2.java
More file actions
43 lines (31 loc) · 750 Bytes
/
Override2.java
File metadata and controls
43 lines (31 loc) · 750 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
package chapter8;
//Methods with differing typw signature are overloaded -not overriden.
class A5 {
int i, j;
A5(int a, int b) {
i = a;
j = b;
}
//display i and j
void show() {
System.out.println("i and j : " + i + " " + j);
}
}
class B5 extends A5 {
int k;
B5(int a, int b, int c) {
super(a, b);
k = c;
}
//Overload Show
void show(String msg) { //display -k this overrides show() in A
System.out.println("k: " + k);
}
}
public class Override2 {
public static void main(String[] args) {
B5 subOb = new B5(1, 2, 3);
subOb.show("This is k : "); // This calls show in B5
subOb.show(); //This calls show in A5
}
}