File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock question help!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock question help!!!!!" Watch "Mock question help!!!!!" New topic
Author

Mock question help!!!!!

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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() { }
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Helen Yu
Greenhorn

Joined: Jul 13, 2000
Posts: 29
Hi,there:
yes, methods can be overloaded both in subclass and base class, not only in subclass.

hyby2000@yahoo.com
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 13, 2000
Posts: 29
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 13, 2000
Posts: 29
I agree with you.
Thanks.
 
Consider Paul's rocket mass heater.
 
subject: Mock question help!!!!!