• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Mock question help!!!!!

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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() { }
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,there:
yes, methods can be overloaded both in subclass and base class, not only in subclass.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Helen Yu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Helen Yu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you.
Thanks.
 
Water proof donuts! Eat them while reading this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic