Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. Working with Object-Oriented ... > Overriding Base-Class Methods

Overriding Base-Class Methods

Say that you have a method in a base class that you need to change. For example, say you have a method named print in the base class Class1 that prints “This is class 1.” Clearly, in the derived class, Class2, the message should say, “This is class 2.”

You can override the base class print method just by redefining it in the derived class. When you override a method in a derived class, the overriding method must have the same prototype (same return type and arguments) as the method you’re overriding.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint