-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpcastingTest.java
More file actions
44 lines (40 loc) · 577 Bytes
/
UpcastingTest.java
File metadata and controls
44 lines (40 loc) · 577 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
package Upcasting
class X
{
int a ;
final int b;
X(){
b = 200;
}
void show(){
System.out.println("X Show");
}
//final void print(){
void print(){
System.out.println("X Print");
}
}
class Y extends X
{
void disp(){
System.out.println("Y Disp");
}
void show(int x){
System.out.println("Y Show");
}
@Override
void print(){
System.out.println("Y Print");
}
}
public class UpcastingTest {
public static void main(String[] args) {
X obj = new Y();
obj.print();
obj.show();
if(obj instanceof Y){
Y obj2 = (Y) obj;
obj2.disp();
}
}
}