Professional Documents
Culture Documents
CONCEPTS
MODULE-3
SYLLABUS
• Introducing Classes: Class fundamentals, Declaration Objects, Assigning Object
Reference Variables, Introducing Methods, Constructors, this keyword, Garbage
Collection.
• Thus, the data for one object is separate and unique from
the data for another.
CLASS FUNDAMENTALS
A Simple Class
• Here is a class called Box that defines three instance
variables: width, height, and depth.
• To access these variables, you will use the dot (.) operator.
• The dot operator links the name of the object with the
name of an instance variable.
DECLARING OBJECTS
Obtaining objects of a class is a two-step process
• Most of the time, you will use methods to access the instance
variables defined by the class.
• This is why width, height, and depth were not used as the
names of the parameters to the Box( ) constructor inside the
Box class.
GARBAGE COLLECTION
• In some languages, such as C++, dynamically allocated
objects must be manually released by use of a delete
operator.
• Single Inheritance
• Multilevel Inheritance
• Hierarchical Inheritance
• Multiple Inheritance
• Hybrid Inheritance
TYPES OF INHERITANCE
SINGLE INHERITANCE
• When a single class gets derived from its base class, then this
type of inheritance is termed as single inheritance.
MULTILEVEL INHERITANCE
• In multilevel inheritance, a subclass
extends from a superclass and then the
same subclass acts as a superclass for
another class.
TYPES OF INHERITANCE
HIERARCHIAL INHERITANCE
• In hierarchical inheritance, multiple subclasses extend from a
single superclass.
TYPES OF INHERITANCE
MULTIPLE INHERITANCE
• In multiple inheritance, a single subclass extends from
multiple superclasses.
TYPES OF INHERITANCE
HYBRID
INHERITANCE
• Hybrid inheritance is a
combination of two or
more types of
inheritance.
BENEFITS OF INHERITANCE
Code Reusability
• Inheritance allows for code reuse and reduces the amount of
code that needs to be written.
Abstraction
• Inheritance allows for the creation of abstract classes that
define a common interface for a group of related classes.