-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpcasting_Example_1.java
More file actions
60 lines (60 loc) · 906 Bytes
/
Copy pathUpcasting_Example_1.java
File metadata and controls
60 lines (60 loc) · 906 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
49
50
51
52
53
54
55
56
57
58
59
60
class Machine
{
void start ()
{
System.out.println("Machine Start....");
}
void run()
{
System.out.println("Machine Run....");
}
}
class Motor extends Machine
{
void start()
{
System.out.println("Motor Start....");
}
void run ()
{
System.out.println("Motor Run....");
}
}
class Generator extends Machine
{
void start()
{
System.out.println("Genarator Start....");
}
void run()
{
System.out.println("Genarator Run....");
}
}
class Upcasting_Example_1
{
public static void main(String [] args)
{
Machine m = new Machine();
m.start();
m.run();
Motor mo = new Motor();
mo.start();
mo.run();
Generator g= new Generator();
g.start();
g.run();//
Machine m1 = new Motor();
m1.start();
m1.run();
Machine m2= new Generator();
m2.start();
m2.run();
Motor m3=(Motor)m1;
m3.start();
m3.run();
Generator g1 = (Generator) m2;
g1.start();
g1.run();
}
}