How to Create Inheritance in JAVA

How to Create Inheritance in JAVA

In this article, you will learn How to Create Inheritance in JAVA.

Example:-

class Vehicle {
  protected String brand = "Samsung";
  public void honk() {
    System.out.println("Mobile, LED!");
  }
}

class Car extends Vehicle {
  private String modelName = "Galaxy";
  public static void main(String[] args) {
    Car myFastCar = new Car();
    myFastCar.honk();
    System.out.println(myFastCar.brand + " " + myFastCar.modelName);
  }
}

Read on Facebook

1 Comment

  • Nita Sharma

    June 25, 2020 - 5:38 am

    Great Article

Leave A Reply