Inheritance Assignment
Inheritance Assignment
3. Replace some existing properties of Vehicle in Car and Replace the some existing properties
Of Car in Duster.
7. Implement the Has-A relationship in between Car class and Engine class
Public void
Class Vehicle{
Int maxspeed=0;
Int noOfWheels;
Int noOfSeats;
System.out.println(“Apply Brake”);
Int maxspeed=100;
Int currentSpeed;
Int noOfWheels=4;
Int noOfSeats=4;
Car(int a){
This.currentSpeed=a;
carEngine.startEngine();
carEngine.stopEngine();
System.out.println(“turn right”);
System.out.println(“turn left”);
Final void horn() { // A final method can be inherited but not overriden . if we try to override
final method in child we will get compiletime error.
System.out.println(“press Horn”);
}
System.out.println(currentSpeed);
@Override
String type=”SUV”;
Int maxSpeed=120;
Duster(int a){
@Override
Public void steerRight() {
@Override
@Override
@Override
System.out.println(“Speed of duster:-“);
Super.speed();
}
// public void horn() { // getting compile time error as its declared final in parent car class
//
// System.out.println(“press Horn”);
// }
//
Class Engine{
System.out.println(“Start ENgineS”);
System.out.println(“Stop EngineS”);
a.brake();
a.speed();
c.steerLeft();
System.out.println(c.maxspeed);