Skip to content

Commit db653da

Browse files
Main Java Code
1 parent 049bb55 commit db653da

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Car-Gears/gears.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
class Car {
2+
3+
public int gear;
4+
public int speed;
5+
6+
public Car(int gear , int speed)
7+
{
8+
this.gear = gear;
9+
this.speed = speed;
10+
}
11+
12+
public void applyBrake(int decrement)
13+
{
14+
speed -= decrement;
15+
}
16+
17+
public void speedUp(int increment)
18+
{
19+
speed += increment;
20+
}
21+
public String toString()
22+
{
23+
return("No. of gears are : " + gear + "\n" + "Speed of SuperCar is : " + speed + " mph");
24+
}
25+
}
26+
27+
class SuperCar extends Car {
28+
29+
public int setHeight;
30+
public SuperCar(int gear, int speed, int rideHeight)
31+
32+
{
33+
super(gear, speed);
34+
setHeight = rideHeight;
35+
}
36+
37+
public void setHeight(int newValue)
38+
{
39+
setHeight = newValue;
40+
}
41+
@Override public String toString()
42+
{
43+
return (super.toString() + "\nRide height is : " + setHeight + " inch");
44+
}
45+
}
46+
public class gears {
47+
public static void main(String[] args) {
48+
SuperCar mb = new SuperCar(5, 180, 15);
49+
System.out.println(mb.toString());
50+
}
51+
}
52+

0 commit comments

Comments
 (0)