Answers to Self-Test Questions

  1. 1. Overriding refers to redefining a base-class method so that it has a different definition in a derived class. Overloading refers to giving a method name two definitions that have different parameter lists. In both cases, the methods have the same name. When you override a method definition, the new method definition given in the derived class has the exact same name, return type, and number and types of parameters. On the other hand, if the method in the derived class were to have a different number of parameters or a parameter of a different type from the method in the base class, the derived class would have both methods. That would be overloading. You can also overload method names in a single class definition ...

Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.