-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCINHEREx2.java
More file actions
81 lines (61 loc) · 2.14 KB
/
CCINHEREx2.java
File metadata and controls
81 lines (61 loc) · 2.14 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
// Ex 2
// Steps 1 Create a Super Class named vehicle with field barand and year and methods startEngine().
// 2 Create a subclass named car that inherits form vechile.
// 3 Add filed called fule type of type String to the car class.
// 4 over ride the stat engine () in the car class print "Car engine starts".
// 5 add a method called drive() to the car class that print "Car is driving".
// 6 Create a truck subclass that also inherits from the vechile class.
// 7 Add a field called load cappasity type int to the truck class.
// 8 Override the start engine() method in truck class to print "Truck engine Starts".
// 9 Add a method called haul() to the truck class prints "Truck is hauling"
class Vehicle{
String brand;
int year;
void StartEngine()
{
}
}
class car extends Vehicle{
String fuletype;
void StartEngine(){
System.out.println("Car Engine Starts");
}
void drive(){
System.out.println("Car is Driving");
}
}
class Truck extends Vehicle{
int load_Capacity;
void StartEngine(){
System.out.println("Truck Engine Starts");
}
void haul(){
System.out.println("Truck is hauling");
}
}
public class CCINHEREx2 {
public static void main(String[] args) {
// For Car
car c1 = new car();
c1.brand = "Audi";
c1.fuletype = "Petrol";
c1.year = 2023;
System.out.println("--- Car Details ---");
System.out.println(c1.brand);
System.out.println(c1.fuletype);
System.out.println(c1.year);
c1.StartEngine();
c1.drive();
System.out.println();
// For Truck
Truck t1 = new Truck();
t1.brand = "Leyland";
t1.year = 2020;
t1.load_Capacity = 20_000;
System.out.println("--- Truck Deatils ---");
System.out.println(t1.brand);
System.out.println(t1.year);
t1.StartEngine();
t1.haul();
}
}