chapter8 parti

19
UNIT- I CHAPTER IN BOOK- 8 PART - I -K. Indhu

Upload: ghuru

Post on 06-Dec-2015

261 views

Category:

Documents


0 download

DESCRIPTION

chapter

TRANSCRIPT

UNIT- ICHAPTER IN BOOK- 8

PART- I

-K. Indhu

K. INDHU

SYLLABUS COVERED HERE• INHERITANCE

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

DIAGRAMMATIC EXAMPLE

K. INDHU

SAMPLE PROGRAM

K. INDHU

SAMPLE PROGRAM

K. INDHU

PUBLIC, PRIVATE

K. INDHU

TYPES IN JAVA

K. INDHU

NO MULTIPLE INHERITANCE IN JAVA THRU CLASS- WHY ?

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.

K. INDHU

USING SUPER

K. INDHU

USING SUPER

K. INDHU

SUPER IN CONSTRUCTOR

K. INDHU

USING SUPER

K. INDHU

MULTI-LEVEL HIERARCHY

E:\JavaPrograms\Exercises\Exercise2\Perso

K. INDHU

SO FAR WE STUDIED…• Inheritance

HAPPY LEARNING!!!