Information Technology Reference
In-Depth Information
This example, written in Java, uses an overloaded constructor, ChatterBox ,
to handle the potential need for a default value to be assigned to its only attribute,
firstName . This common usage of overloading allows software engineers to
apply a minimalist approach to object creation, and avoid writing unnecessary
code. In the case of the ChatterBox class, if a string argument is passed with the
constructor, that string will be assigned to the firstName attribute. On the other
hand, if no string is passed, firstName is given a default value, ''Chatty''.
The class description above also demonstrates the second usage of overloading:
convenience. The three implementations of the sayHello method all serve a
slightly different, but related purpose. Overloading is used here to provide logical
Search WWH ::




Custom Search