A good answer might be:The signature of a method is the name of the method and its parameter list, something like this: The return type is not part of the signature. The names of the parameters do not matter, just their types.someMethod( int, double, String ) | ||
SignatureThe name of a method is not enough to uniquely identify it, since several classes in a hierarchy might use the same name. Using the types in the parameter list says more carefully which method you want. The return type can't be used because of the following situation: Say that there are two someMethod() methods: one defined in a parent class like this:
and another method defined in a child class like this:
Somewhere else in the program there is an invocation of someMethod(): The value on the left of the = can be either int or short, since both can be converted to a double value needed for the double variable w. So the statement gives the compiler no information about the type of value returned by someMethod.double w = child.someMethod( 12, 34.9, "Which one?" ); Of course the names of the parameters in the two definitions of someMethod() can't be used to decide which one to use because the invocation uses actual values like 12 and 34.9. So the two definitions of someMethod() have the same signature; they are not different enough to be told apart. Because of this, the method defined in the child will override the method defined in the parent. The invocation will cause the child's method to run. | ||
QUESTION 2:Do these two methods have different signatures:
Click Here after you have answered the question
|