What is inheritance in Java?

What is inheritance in Java?

Answer

Inheritance means that one class can inherit (“extends”) another class. Thus, you can reuse the code from the class from which they are inherited. The existing class is known as superclass and the one being created is known as subclass. They also say parent and child.

public class Animal {
   private int age;
}

public class Dog extends Animal {

}

where Animal is parent and Dogchild.

Оцените статью
ASJAVA.COM
Добавить комментарий

Your email address will not be published. Required fields are marked *

*

code