Inheritance Overview - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Inheritance Overview

Description:

Derived Class and Base Class ... The Class Object ... One of the methods in that class is called toString which suppose to return all ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 5
Provided by: derek94
Category:

less

Transcript and Presenter's Notes

Title: Inheritance Overview


1
Inheritance Overview
  • Inheritance is another one of the big OOP
    concepts
  • The idea is that we can define a very general
    class and then define more specialized classes
    that inherit the attributes (data) and operations
    (methods) of the general class.

2
Derived Class and Base Class
  • When we define a class that inherits data and
    methods from another class we call the class that
    inherits the derived class and the one being
    inherited from the base class.
  • Example
  • We may have a truck class (derived) that
    inherits data and methods from a vehicle class
    (base).

3
Method Overriding
  • In some cases we may have methods in the derived
    class that have the same method signature as what
    is in the base class.
  • What happens in this case is that the method in
    the derived class overrides the method in the
    base class.
  • How is this different from method overloading?

4
The Class Object
  • There is one class that every class is a
    descendant from and that is the predefined class
    Object.
  • One of the methods in that class is called
    toString which suppose to return all the data
    (instance variables) as a String.
  • Sounds nice huh? Well, it usually does not work
    the way we would like
  • What can we do? Override it!
Write a Comment
User Comments (0)
About PowerShow.com