CSCI111: Chapter 14

CSCI111: Notes Chapter 6 and 8
Inheritance and OO Design

Method signatures

Remember that a signature for a method is the information that it provides in its definition name: class template

How java determines which method to use is determined by

  1. the type of instance on which the method was called
  2. the name of the method and
  3. the parameter types
Note that all of this information would be in the call made. Example: The question was, can we have two methods with the same signature and only differing in return type?

The answer is no.     Why?

Think about it. Consider ambiguity.

How would Java know which one is wanted? It does not get into your code and determine what it is you expect to return. The big difference between the return type changing and the parameters changing in overloading is that the user has to call the method with parameter values and hence java knows what type of things these are. All of the above methods could be called by:

It cannot guess ahead to what you expect to return.

Read Chapter 14 Section 3

Feature Accessibility

Public: anyone can see

Private: only instances of the object can see

Protected: instances of the object and its subclasses can see

Restricted (not really a name ... but is the default when nothing is named): accessible anywhere in the package containing the class in which the feature is defined. The default package is the directory.