Java Essentials - Inheritance in java
Show More Show Less View Video Transcript
0:00
Inheritance in Java is a topic in this session
0:05
Inheritance means one class will acquire the properties of another class. The class form where these properties will be coming will be known as the best class or the super class
0:16
And the property which will be inherited to another class, which will be used in another class
0:21
will be known as the derived class, child class or subclass. So, inheritance supports reusability of the programming code
0:29
of the programming code. So let us go for further discussion on this inheritance. Inheritance can be
0:36
defined as a process where one class acquires the property of another predefined class. And with the
0:43
use of inheritance, the information is made manageable in a hierarchical order. So using this inheritance
0:50
we can enforce the reusability of the programming code. So what will happen? We can define
0:55
one class where the basic properties will be defined, the basic operations will be defined and those properties and operations can be inherited onto other classes
1:04
as when required Let us suppose I have defined one class that is a person So person has got some basic member variables and the basic member functions So now a dancer is also a person a cricketer is also a person and teacher like myself
1:21
is also one person. So we are having some dedicated separate properties and functions will be there, but the basic
1:27
properties of the person class will be always common to all of them
1:32
So that is the basic inherent feature of this inheritance. The class which inherits the property
1:39
of other class is known as a subclass, derived class, also known as the child class. But in our
1:47
Java we usually use the term subclass. And the class whose properties are inherited is known
1:53
as a super class, base class, or the parent class. But in Java, we prefer to like to call it
1:59
as super class. To define a derived class, the extends keyword will be used in our Java code
2:06
And it inherits the property of the base class, which, properties will be inherited that will be defined depending upon the scope of those properties
2:15
that means in under which scope private public or protected under which scope this particular
2:20
or in the default scope rather in which scope these variables or the methods are defined they that will decide whether the property or the respective methods will be inherited to the child class or subclass or not
2:35
In Java, multiple inheritance is not possible. In case of multiple inheritance, we'll be having multiple base classes and only one derived class
2:43
So that is not directly possible in case of Java. Otherwise, single inheritance, multi-level inheritance, hierarchical inheritance, then hierarchical
2:53
multiple that is known also known as a hybrid inheritance then hierarchical then also multiple
2:59
hierarchical so different kinds of inheritances are possible but one kind of inheritance is not allowed in
3:05
our java programming not directly that is our multiple inheritance so let us go for further
3:10
discussions with some practical demonstration on this inheritance in this demonstration we shall be
3:17
discussing about java inheritance at first we are defining one base class the name of
3:23
the best class is employee which is having protected double salary and that is
3:27
about 30,000 D here D stands for the double so this particular 30,000 is of the type
3:34
double here so here we're having one constructor the name of the constructed will be
3:39
same as that of the class name that is our employee and one line of code is here to print one message this developer is nothing but a subclass and this subclass means the inherited class and where
3:52
the base class or the super class here is the employee here also we are defining another class
3:58
that is a subclass or inherited class and this particular subclass is also having the same base class
4:04
that is employee in the both cases we have defining bonus here it is 20 000 here it is 10 000
4:10
here it is 20,000 and this is the developer constructor and this is a tester constructor
4:15
and only one string will get printed in the constructor from the constructor body so
4:21
this is the total structure of the classes and here we are having one display salary
4:26
you can find that this particular salary was under the protected section that means
4:32
they are inheritable so that's why this salary can be accessed from the derived
4:37
class that is our developer and this test are also this salary is accessible so here when you are printing the display
4:45
salary we're just adding the salary and the bonus the salary and the bonus is nothing but the
4:51
instance variable of this developer and salary is the inherited variable inherited instance
4:57
variable and that is a salary and they are getting
#Programming
#Java (Programming Language)
#Jobs & Education
#Education
#Inheritance & Estate Planning
#Computer Education

