Lecture-34 - Method Overriding • In a class hierarchy when a method in a subclass has the same return type and signature as a method in its

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 37 Method Overriding • In a class hierarchy, when a method in a subclass has the same return type and signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 38 Method Overriding • When an overridden method is called from within a subclass, it will always refer the version defined by the subclass.
Background image of page 2
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 39
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 40
Background image of page 4
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 41 Method Overriding • Method overriding occurs only when the return types and signatures of the two methods are identical. • If they are not, then the two methods are simply overloaded.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 42
Background image of page 6
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 43 Overridden Methods and Polymorphism • Method overriding forms the basis for one of Java’s most powerful concepts: dynamic method dispatch . • Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time rather than compile time.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 44
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2010 for the course CSE IT115 taught by Professor Rblenin during the Spring '10 term at Punjab Engineering College.

Page1 / 30

Lecture-34 - Method Overriding • In a class hierarchy when a method in a subclass has the same return type and signature as a method in its

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online