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

Overloading Constructors

Constructors enable you to send parameters when you build an object, but sometimes you don’t want to send any parameters. You can create an object in one of several ways. Classes can have more than one constructor, which makes them even more flexible. If you have more than one constructor, it is known as overloading your constructors.

Viewing the Improved Critter Class

You can make another version of the Critter class that has several constructors with different sets of parameters. Take a look at this version of the critter to see how it works. I’m showing only the constructors in this code listing because nothing else changes.


  

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