Child Class:: The Class That Extends The Features of Another Class Is Known As Child Class, Sub Class or Derived Class
Child Class:: The Class That Extends The Features of Another Class Is Known As Child Class, Sub Class or Derived Class
Child Class:: The Class That Extends The Features of Another Class Is Known As Child Class, Sub Class or Derived Class
The process by which one class acquires the properties(data members) and
functionalities(methods) of another class is called inheritance. The aim of
inheritance is to provide the reusability of code so that a class has to write only
the unique features and rest of the common properties and functionalities can be
extended from the another class.
Child Class:
The class that extends the features of another class is known as child class, sub
class or derived class.
Parent Class:
The class whose properties and functionalities are used(inherited) by another
class is known as parent class, super class or Base class.
Inheritance is a process of defining a new class based on an existing class by
extending its common data members and methods.
Inheritance allows us to reuse of code, it improves reusability in your java
application.
Note: The biggest advantage of Inheritance is that the code that is already
present in base class need not be rewritten in the child class.
Syntax: Inheritance in Java
To inherit a class we use extends keyword. Here class XYZ is child class and class
ABC is parent class. The class XYZ is inheriting the properties and methods of ABC
class.
Output:
Beginnersbook
Teacher
Physics
Teaching
Based on the above example we can say that PhysicsTeacher IS-A Teacher. This
means that a child class has IS-A relationship with the parent class. This is
inheritance is known as IS-A relationship between child and parent class
Example:
As displayed in the above figure, Programmer is the subclass and Employee is the
superclass. Relationship between two classes is Programmer IS-A Employee.It
means that Programmer is a type of Employee.
class Employee{
float salary=40000;
int bonus=10000;
Output:
Programmer salary is:40000.0
Bonus of programmer is:10000
CLASS TASK: