You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
3
+
Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
4
+
Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.
5
+
Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.
6
+
# The syntax of Java Inheritance
7
+
class Subclass-name extends Superclass-name
8
+
{
9
+
//methods and fields
10
+
}
11
+
The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.
12
+
13
+
# In the terminology of Java, a class which is inherited is called a parent or superclass, and the new class is called child or subclass.
14
+
Java Inheritance Example
15
+
# Inheritance in Java
16
+
- As displayed in the above figure, Programmer is the subclass and Employee is the superclass. The relationship between the two classes is Programmer IS-A Employee. It means that Programmer is a type of Employee.
0 commit comments