Answer to Question #254519 in Java | JSP | JSF for Tege

Question #254519

Write the java program in the following features of OOP:

1,Encapsulation

2,Polymorphism

3,Inheritance

4,Abstraction 


1
Expert's answer
2021-10-22T00:48:52-0400
public abstract class Vehicle {
    private String color;

    public Vehicle(String color) {
        this.color = color;
    }

    public abstract void useHorn();
}


public class Car extends Vehicle {
    private String frontLicensePlate;
    private String rearLicensePlate;

    public Car(String color) {
        super(color);
    }

    @Override
    public void useHorn() {
        System.out.println("Bip-bip");
    }

    public void addLicensePlate(String frontLicensePlate, String rearLicensePlate) {
        this.frontLicensePlate = frontLicensePlate;
        this.rearLicensePlate = rearLicensePlate;
    }

    public void addLicensePlate(String licensePlate) {
        frontLicensePlate = licensePlate;
        rearLicensePlate = licensePlate;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS