-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorBike.java
More file actions
45 lines (42 loc) · 1 KB
/
Copy pathMotorBike.java
File metadata and controls
45 lines (42 loc) · 1 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
package oopsConcepts;
//This Program demonstrates Inheritance
public class MotorBike {
public int gear;
public int speed;
public MotorBike(int gear, int speed)
{
this.gear = gear;
this.speed = speed;
}
public void applyBrake(int decrement)
{
speed -= decrement;
}
public void speedUp(int increment)
{
speed += increment;
}
public String toString()
{
return("No of gears are :" + gear + "\n" + "speed of Motor Bike is " + speed);
}
}
class GearedMotorBike extends MotorBike
{
public int seatHeight;
public GearedMotorBike(int gear,int speed,int startHeight)
{
super(gear, speed);
seatHeight = startHeight;
}
public void setHeight(int newValue)
{
seatHeight = newValue;
}
@Override
public String toString()
{
return (super.toString()+
"\nseat height is "+seatHeight);
}
}