chapter8 parti
DESCRIPTION
chapterTRANSCRIPT
K. INDHU
GOALS1. Inheritance Definition2. Inheritance Syntax3. Inheritance Diagrammatic Example4. Inheritance Sample Program5. Public, Private in Inheritance6. Types of Inheritance in Java7. No Multiple Inheritance in Java- Why ?8. Using “super”9. Note- “super” in constructor during inheritance10. THREE USAGES of “super”11. Multi-Level Hierarchy
K. INDHU
INHERITANCE DEFINITION• DEFINITION->• “Inheritance in java is a mechanism in which one object acquires all
the properties and behaviors of parent object.”
• Inheritance represents the “IS-A relationship, also known as parent-child relationship”.
• WHY USE INHERITANCE IN JAVA?• (1) For Method Overriding (runtime polymorphism can be achieved).• (2) For Code Reusability.
• In the terminology of Java-– a class that is inherited is called a super class.– The new class is called a subclass.
K. INDHU
INHERITANCE SYNTAX• The general form of a class declaration that
inherits a superclass is shown here:
• class Subclass-name extends Superclass-name • { • //methods and fields • }
• The extends keyword indicates that you are making a new class that derives from an existing class.
K. INDHU
USING SUPERI. Whenever a subclass needs to refer to its immediate super-
class, it can do so by use of the keyword "super".
II. Whenever the instance of subclass is created, an instance of parent class is created implicitly i.e. referred by "super" reference variable.
III. USAGE OF JAVA "super" KEYWORD->• (i) super is used to refer immediate parent class instance
variable.• (ii) super() is used to invoke immediate parent class
constructor.• (iii) super is used to invoke immediate parent class method.