lecture-33 - Object Oriented Programming Java –...

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

View Full Document Right Arrow Icon
Object Oriented Programming Java – Inheritance and Polymorphism
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 2 Introduction • In Java, a class that is inherited is called a superclass . • The class that does the inheriting is called a subclass . • A subclass is a specialized version of a superclass. – It inherits all of the variables and methods defined by the superclass and adds the own, unique elements
Background image of page 2
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 3 Inheritance Basics • Java supports inheritance by using the extends keyword. class subclass-name extends superclass-name { //body of class } • Java does not support the inheritance of multiple superclasses into a single subclass. – But any level of class hierarchy (single- inheritance) is possible in Java.
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 4 Example • Next example – Create a superclass TwoDShape which stores the width and height of a 2-dimensional object and a subclass called Triangle .
Background image of page 4
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 5
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 6
Background image of page 6
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 7
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 8 Example Triangle Class: showStyle( ) area( ) style showDim( ) height width
Background image of page 8
Object Oriented Programming Java - Inheritance and Polymorphism Winter 2006 R.B. Lenin DA-IICT 9 Private Members Access • Inheriting a class
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

lecture-33 - Object Oriented Programming Java –...

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

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