The question below is not clear to me. Does the question relate to overriding. It does not look so to me as the answers are 1 and 3. Another question : Can the subclass overload the base class methods. If a base class has a method defined as void method() { } Which of the following are legal prototypes in a derived class of this class. Select all correct answers. 1. void method() { } 2. int method() { return 0;} 3. void method(int i) { } 4. private void method() { }
IMHO the answer is 1,3. 1 is overridding totally without changing access modifier and is allowed 2 is false because it is only changing the return type. 3 is overloading because it changes the arugment list 4 is false an overridding method cannot change the access modifier to be more private.
thanks carl and helen!!! i have a question derived out of ur answers. so the question is about overriding and the answer 2 becomes a totally different method in a subclass. Is answer 3 not a new method in the subclass as it has a argument.
hi,there: ///////////////////////////////////////////////// i have a question derived out of ur answers. so the question is about overriding and the answer 2 becomes a totally different method in a subclass. Is answer 3 not a new method in the subclass as it has a argument. //////////////////////////////////////////////// Answer 2 is not legal, because only with different return type are not considered as Overloading or Overriden. The compiler will not let you pass if you write code like answer 2. Answer 3 is not a new method in the subclass as it has a argument but it is the overloading version of base class. Feel free to conrect me. Thanks.
hi helen, According to ur explanation if I modify answer 2 by putting in an arguement as below. Now, can answer 2 be the right answer? 2. int method(String s) { return 0;} let me know ur thoughts on this. thanks Rakhee Arun