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:
> private methods a re never inherited! > to override a method you should inherit the one that is being overriden.
in your code you are not overriding as the method f1 is not inherited ... try creating a parent class object in child class & access the private method. it won't compile. in your code you are just declaring a new method in child class' hope it hlps
BTW ... next time use the UBB code blocks for code & give a better title for the post so that it helps others [ July 31, 2008: Message edited by: Milan Sutaria ]