{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture7 - CS116 OBJECTORIENTED PROGRAMMINGII LECTURE7...

Info icon This preview shows pages 1–11. 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
Image of page 1

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

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

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

View Full Document Right 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
Image of page 8
Multiple Inheritance 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
Image of page 9

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

View Full Document Right Arrow Icon
Multiple Inheritance The concept of multiple inheritance is  shown below (even though Java does not  allow it).
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern