Introducing Java Inheritance Concepts

 



Inheritance

 Java Inheritance (Subclass and Superclass)

In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories.


  • subclass (child) - the class that inherits from another class
  • superclass (parent) - the class being inherited from

To inherit from a class, use the 'extends' keyword.

class BMWCar() {

tires;

engine;

lights;

doors;

break liner;

seat;

steering wheel;


drive() {}

reverse() {}

break() {}

signal light() {}

horns() {}

}


class BMWModernCar() {

}


Taking the things of one class to another class is called Inheritance. It needs to create a relationship between the two classes. Then the first class is called "Super Class" and the new class is called "Sub Class".

GitHub Projects


Comments

Popular posts from this blog

Introducing Java Encapsulation Concept

Introducing Java Interfaces Concept

Introducing Java Method Overriding And Super Keyword