-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_26.java
More file actions
84 lines (71 loc) · 2.07 KB
/
Practical_26.java
File metadata and controls
84 lines (71 loc) · 2.07 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
84
/*Question := Create a class Vehicle, which has single variable NoOfWheels. Develop
two subclasses, TwoWheeler and FourWheeler. Develop subclasses of
these 2 subclasses. Create instances of these classes and print
appropriate details. (use super keyword). */
class Vehicle {
protected int noOfWheels;
public Vehicle(int wheels) {
noOfWheels = wheels;
}
}
class TwoWheeler extends Vehicle {
public TwoWheeler() {
super(2);
}
}
class FourWheeler extends Vehicle {
public FourWheeler() {
super(4);
}
}
class Scooter extends TwoWheeler {
public Scooter() {
String type = "Scooter";
System.out.println("Type of vehicle := " + type);
System.out.println("Number of wheels := " + noOfWheels);
System.out.println();
}
}
class Motorcycle extends TwoWheeler {
public Motorcycle() {
String type = "Motorcycle";
System.out.println("Type of vehicle := " + type);
System.out.println("Number of wheels := " + noOfWheels);
System.out.println();
}
}
class Car extends FourWheeler {
public Car() {
String type = "Car";
System.out.println("Type of vehicle := " + type);
System.out.println("Number of wheels := " + noOfWheels);
System.out.println();
}
}
class SUV extends FourWheeler {
public SUV() {
String type = "SUV";
System.out.println("Type of vehicle := " + type);
System.out.println("Number of wheels := " + noOfWheels);
System.out.println();
}
}
public class Practical_26 {
public static void main(String[] args) {
Scooter sc = new Scooter();
Motorcycle mc = new Motorcycle();
Car car = new Car();
SUV suv = new SUV();
}
}
/*
Output :=
Type of vehicle := Scooter
Number of wheels := 2
Type of vehicle := Motorcycle
Number of wheels := 2
Type of vehicle := Car
Number of wheels := 4
Type of vehicle := SUV
Number of wheels := 4
*/