-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram#C.java
More file actions
41 lines (38 loc) · 991 Bytes
/
Program#C.java
File metadata and controls
41 lines (38 loc) · 991 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
/* Create a class Vehicle with attributes like speed and fuelType. Create subclasses Car and Bike that inherit from Vehicle and add additional attributes.
Speed:60
fuelType:Petrol
Color:Red
-------------------
Speed:60
fuelType:Petrol
Color:Blue
*/
class Main {
public static void main(String [] args)
{ Car s1 = new Car();
Bike s2 = new Bike();
s1.display();
s2.display();
}
}
class Vehicle {
int speed = 60;
String fuelType = "Petrol";
}
class Car extends Vehicle {
String color = "Red";
void display(){
System.out.println("Speed:"+speed);
System.out.println("fuelType:"+fuelType);
System.out.println("Color:"+color);
System.out.println("-------------------");
}
}
class Bike extends Vehicle {
String color = "Blue";
void display(){
System.out.println("Speed:"+speed);
System.out.println("fuelType:"+fuelType);
System.out.println("Color:"+color);
}
}