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

4.10. Overriding Behavior

Now that you've seen methods and access modifiers in action, allow me to return to inheritance for a moment. When using inheritance, sometimes you want to make the child class do something that the parent class does, but differently. For example, you might want to make a QuietSeagull, which makes a much softer sound when it squawks. The superclass, or base class, of Seagull already has a squawk() behavior, and by extending that class, your new subclass inherits that behavior.

Plain vanilla inheritance provides the new subclass with a starting point, which is all the public, internal, and protected properties and methods of the base class. But sometimes adding onto this starting point is not enough. Sometimes you have to change it.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free 10-Day Trial


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