-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphismProgram.java
More file actions
83 lines (73 loc) · 1.46 KB
/
PolymorphismProgram.java
File metadata and controls
83 lines (73 loc) · 1.46 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//Program to design a vehicle class hierarchy in Java, and develop a program to demonstrate Polymorphism.
class Vehicle
{
String regno;
int model;
Vehicle(String r, int m)
{
regno = r;
model = m;
}
void display()
{
System.out.print("\nRegistration no: "+regno);
System.out.print("\nModel no: "+model);
}
}
class Twowheeler extends Vehicle
{
int noofwheels;
Twowheeler(String r, int m, int n)
{
super(r,m);
noofwheels = n;
}
void display()
{
System.out.print("\nTwo wheeler tvs");
super.display();
System.out.print("\nNo. of wheels: " + noofwheels);
}
}
class Threewheeler extends Vehicle
{
int noofwheels;
Threewheeler(String r,int m,int n)
{
super(r,m);
noofwheels = n;
}
void display()
{
System.out.print("\nThree wheeler auto");
super.display();
System.out.print("\nNo. of wheels: " +noofwheels);
}
}
class Fourwheeler extends Vehicle
{
int noofwheels;
Fourwheeler(String r,int m,int n)
{
super(r,m);
noofwheels=n;
}
void display()
{
System.out.print("\nFour wheeler car");
super.display();
System.out.print("\nNo. of wheels: " + noofwheels);
}
}
class PolymorphismProgram
{
public static void main(String arg[])
{
Twowheeler t1 = new Twowheeler("KA74 12345", 1,2);
Threewheeler th1 = new Threewheeler("KA74 54321", 4,3);
Fourwheeler f1 = new Fourwheeler("KA34 45677",5,4);
t1.display();
th1.display();
f1.display();
}
}