The following question is from the book "A Programmer's Guide to
Java Certification" by Khalid A. Mughas and Rolf W. Rasmussen. I have a
couple of issues with the following question:
Which statment is true?
Select the one correct answer.
(a) Private methods cannot be override in subclass.
(b) A subcanll can override any method in a subclass.
(c) An orderriding method can delcare that it throw more excpetions than
the method it is overriding.
(d) The paramter list of an overriding method must be a subset of the
parameter list of the method that it is overriding.
(e) The orerriding method can have a different return type than the
orderridden method.
First, I claim that c and e are not correct. I also claim that for any
set S, S is a subset of S. In addition, when a method is overriden its
parameter list must be the same as the method it is overriding. Therefore,
I claim that c is a correct choice. Now, please consider the following program:
class
test {
private int f1()
{
return 5;
}
}
class d1 extends test {
int f1()
{
return 0;
}
};
This program compiles for me and I claim that in this case f1 is being overriden. Therefore, b is a correct answer.
The book says that the correct answer is a. I am hoping that somebody can comment.
Thanks
Bob