06Inheritance - ITI 1121 Introduction to Computing II...

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

View Full Document Right Arrow Icon
ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of January 23, 2011 Abstract Inheritance Introduction Generalization/specialization * These lecture notes are meant to be looked at on a computer screen. Do not print them unless it is necessary.
Background image of page 1

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

View Full Document Right Arrow Icon
Summary We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems. The data, and the methods that act upon the data, are encapsulated into a single entity called the object. The instance variables define the properties or state of an object. In particular, we have seen that OOP provides mechanisms to control the visibility of the methods and the variables. The methods and variables that are public define the interface of the object. Having the interface clearly defined allows the implementers and the users of the class to work independently; the creator can change the implementation of the class, as long as it does not affect the interface, and the programs developed by the users will continue to work. As a general principle, in CS II, all the instance variables should be declared private.
Background image of page 2
If the value of a variable needs to be accessed (read or mutated) from outside the class, then the interface of the object will include setter and getter methods. This principle will allow us to maintain the integrity of the objects. The class specifies the content of the objects but it also exists during the execution of a program. Each object knows the class from which it was instantiated from (is an instance of). No matter how many instances there are, 0, 1 or n , there is only one copy of the class. Class variables and methods are shared by all instances of a class. In today’s lecture, we look at other important features of object-oriented programming that help organizing and maintaining large software systems: inheritance and polymorphism .
Background image of page 3

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

View Full Document Right Arrow Icon
Inheritance OO languages, in general, also offer other tools to structure large systems. Inheritance is one of them. Inheritance allows to organize the classes hierarchically. Inheritance favors code reuse !
Background image of page 4
Inheritance The class immediately above is called the superclass or parent class while the class immediately below is called the subclass , child class or derived class . Bird Pigeon is a In this example, Bird is the superclass of Pigeon , i.e. Pigeon “is a” subclass of Bird .
Background image of page 5

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

View Full Document Right Arrow Icon
Inheritance Bird Pigeon is a In Java, the “is a” relationship is expressed using the reserved keyword extends , as follows: public class Pigeon extends Bird { ...
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 40

06Inheritance - ITI 1121 Introduction to Computing II...

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

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