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

Chapter8 PartI

Dec 06, 2015

Download

Documents

Ghuru

chapter
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter8 PartI

UNIT- ICHAPTER IN BOOK- 8

PART- I

-K. Indhu

Page 2: Chapter8 PartI

K. INDHU

SYLLABUS COVERED HERE• INHERITANCE

Page 3: Chapter8 PartI

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

Page 4: Chapter8 PartI

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.

Page 5: Chapter8 PartI

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.

Page 6: Chapter8 PartI

K. INDHU

DIAGRAMMATIC EXAMPLE

Page 7: Chapter8 PartI

K. INDHU

SAMPLE PROGRAM

Page 8: Chapter8 PartI

K. INDHU

SAMPLE PROGRAM

Page 9: Chapter8 PartI

K. INDHU

PUBLIC, PRIVATE

Page 10: Chapter8 PartI

K. INDHU

TYPES IN JAVA

Page 11: Chapter8 PartI

K. INDHU

NO MULTIPLE INHERITANCE IN JAVA THRU CLASS- WHY ?

Page 12: Chapter8 PartI

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.

Page 13: Chapter8 PartI

K. INDHU

USING SUPER

Page 14: Chapter8 PartI

K. INDHU

USING SUPER

Page 15: Chapter8 PartI

K. INDHU

SUPER IN CONSTRUCTOR

Page 16: Chapter8 PartI

K. INDHU

USING SUPER

Page 17: Chapter8 PartI

K. INDHU

MULTI-LEVEL HIERARCHY

E:\JavaPrograms\Exercises\Exercise2\Perso

Page 18: Chapter8 PartI

K. INDHU

SO FAR WE STUDIED…• Inheritance

Page 19: Chapter8 PartI

HAPPY LEARNING!!!