CLASSES AND OBJECTS
•A class is a blueprint from which individual objects are created.
colour
name
INTRODUCTION TO INHERITANCE
•Inheritance in javais a mechanism in which one class acquires all the properties and behaviours of
another class.
•Sub Class :The class that inherits properties and behaviours from another class is called Sub class or
Derived Class.
•Super Class : The class whose properties and behaviours are inherited by sub class is called Base
Class or Super class.
•Syntax of Java Inheritance
classSubclass-nameextendsSuperclass-name
{
//methodsandfields
}
INTRODUCTION TO INHERITANCE
•Why and when to use inheritance?
TYPES OF INHERITANCE
•On the basis of class, there can be mainly three types of inheritance in java:
1.Single
2.Multilevel
3.Hierarchical
MULTIPLE AND HYBRID INHERITANCE
Class A Class B
Class C
Class B Class C
Class D
Class A
ADVANTAGES AND DISADVANTAGES
ADVANTAGES
•Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of
inherited class.
•Reusability enhanced reliability. The base class code will be already tested and debugged.
•As the existing code is reused, it leads to less development and maintenance costs.
DISADVANTAGES
•Inherited functions work slower than normal function as there is indirection.
•Improper use of inheritance may lead to wrong solutions.
•Often, data members in the base class are left unused which may lead to memory wastage.
•Inheritance increases the coupling between base class and derived class. A change in base class will affect all the
child classes.