lecture7 - CS116 OBJECTORIENTED PROGRAMMINGII LECTURE7...

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

View Full Document Right Arrow Icon
CS 116 OBJECT ORIENTED  PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS Copyright:  Spring 2010/ Illinois Institute of Technology/George Koutsogiannakis
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last week’ s topics Continue with multi dimensional arrays Multidimensional Arrays ArrayList 2
Background image of page 2
This Lecture ’s topics Inheritance Concepts Inheritance Design Inherited Members of a Class Subclass Constructors Overriding Inherited Methods 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Inheritance Concepts A common form of reuse of classes is  inheritance We can organize classes into   hierarchies  of  functionality The class at the top of the hierarchy  ( superclass ) defines instance variables and  methods common to all classes in the  hierarchy We derive a  subclass , which  inherits   behavior and fields from the  superclass 4
Background image of page 4
What is the Advantage? If Class B inherits Class A  then: All the methods that class A has are also members of  Class B. All public instance variables of Class A are also  members  of Class B. That means that Class B can use these public  members of Class A without using an objcet of Class  A to invoke them.  In this example Class A is called the  SUPERCLASS and Class B is called the  SUBCLASS 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
A Sample Vehicle Hierarchy This hierarchy is depicted using a Unified  Modeling Language (UML) diagram. In UML diagrams, arrows point from the  subclass to the superclass. 6
Background image of page 6
Superclasses and Subclasses A superclass can have multiple  subclasses Subclasses can be superclasses of other  subclasses A subclass can inherit directly from only  one superclass- Multiple inheritance is not allowed in Java (C+ + allows multiple inheritance). All classes inherit from the  Object  class 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
Superclasses and Subclasses In this example: If our superclass Vehicle has methods  calculateV and calculateD then All the subclasses (Automobile, Truck, Pickup,  TractorTrailer) get to use these methods  without an object of Vehicle to invoke them. i.e  I class Pickup to calculate the velocity of a  Pickup object we will call:    double vel=calculateV(); 8
Background image of page 8
In the examples thus far we used Single  Inheritance: That means that a subclass can only inherit  from a one superclass. Multiple Inheritance means that a subclass  can inherit from more than one superclass. Some languages allow that (i.e. C++). Java DOES Not allow it. 9
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.

This note was uploaded on 06/27/2010 for the course CS 116 taught by Professor Koutsogiannakis during the Summer '08 term at Illinois Tech.

Page1 / 38

lecture7 - CS116 OBJECTORIENTED PROGRAMMINGII LECTURE7...

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