BCA : 5TH SEM
BCA-S301T : JAVA PROGRAMMING AND DYNAMIC WEBPAGE DESIGN
RAM GOPAL GUPTA
ASSOCIATE PROFESSOR
DISCLAIMER
Contents of the tutorial, shown image(s) (if shown here) and movie(s) (if shown here)
are just compilation of research work/creation of various authors/organizations.
Contents are collected from various research papers, reports, books, websites and other
sources.
BCA-S301T : JAVA PROGRAMMING AND DYNAMIC WEBPAGE DESIGN
UNIT-1
INHERITANCE IN JAVA
Inheritance can be defined as the process where one class acquires the properties (methods and
fields) of another. With the use of inheritance the information is made manageable in a hierarchical
order.
The class which inherits the properties of other is known as subclass (derived class, child class) and
the class whose properties are inherited is known as superclass (base class, parent class).
The idea behind inheritance in Java is that you can create new classes that are built upon existing
classes. When you inherit from an existing class, you can reuse methods and fields of the parent
class. Moreover, you can add new methods and fields in your current class also.
Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
Why use inheritance in java:
For Method Overriding (so runtime polymorphism can be achieved).
For Code Reusability.
Terms used in Inheritance:
Class: A class is a group of objects which have common properties. It is a template or
blueprint from which objects are created.
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.
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.
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.
BCA-S301T : JAVA PROGRAMMING AND DYNAMIC WEBPAGE DESIGN
extends Keyword
extends is the keyword used to inherit the properties of a class. Following is the syntax of extends
keyword.
Syntax
class Super {
.....
.....
}
class Sub extends Super {
.....
.....
}
Types of inheritance in java
On the basis of class, there can be three types of inheritance in java: single, multilevel and
hierarchical.
In java programming, multiple and hybrid inheritance is supported through interface only. We will
learn about interfaces later.
BCA-S301T : JAVA PROGRAMMING AND DYNAMIC WEBPAGE DESIGN
Note: Multiple inheritance is not supported in Java through class.
When one class inherits multiple classes, it is known as multiple inheritance.
For Example:
BCA-S301T : JAVA PROGRAMMING AND DYNAMIC WEBPAGE DESIGN