-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
42 lines (30 loc) · 744 Bytes
/
Test.java
File metadata and controls
42 lines (30 loc) · 744 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
package casting;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Animal a = new Animal();
System.out.println("1.Animal - Animal\t");
a.display();
Dog a1 = new Dog();
System.out.println("2. Dog - Dog\t");
a1.display1();
a1.display();
Animal a2 = new Dog(); //upcasting
System.out.println("3.Animal - Dog\t");
a2.display();
Dog d= new Dog(); //downcast
Animal an =(Dog) d;
Dog d1 = (Dog) an;
System.out.println("4.Dog - Animal \t");
d1.display();
d1.display1();
Dog d9 = (Dog) new Animal();
System.out.println("Dog - Animal \t");
d9.display();
Animal an1 =new Dog();
Dog d10 = (Dog) an;
}
}