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 Two Mock Exam Q 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 "Two Mock Exam Q" Watch "Two Mock Exam Q" New topic
Author

Two Mock Exam Q

Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Two questions from John Hunt Mock exam.

Q.No.25.

Which of the following is a legal return type of a method overloading the following method:
public void add(int a) {�}
A. void
B. int
C. Can be anything
Select the most appropriate answer.

Ans given is C.
It can�t be anything, because if it is void, it will be overriding.

Q.No. 30

What class must an inner class extend:

A. The top level class
B. The Object class
C. Any class or interface
D. It must extend an interface

Select the most appropriate answer
Ans. Given is C.
I don�t think it is C. Because - 1.Class cannot extend interface. 2.final class can not be extended.

Looks like, A and B is correct.

Please confirm both questions.

Thank you in advance.


"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411

It can�t be anything, because if it is void, it will be overriding.


Is public void add (int a, String s) method overload or override for the method public void add (int a) ? That should give you hint why the answer is return type can be anything

Answer to the second question I guess u r correct.


Hope that helps ya.


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Muralidhar Mandapati
Greenhorn

Joined: Nov 14, 2004
Posts: 23
For the second question..
I think that inner class can extends any class other than final classes and can implement any interface.
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Thank you for your reply Jay / Murladhar,
Agree, Jay, public void add (int a, String s) is not overriding, but public void add(int a) is..
So, it is true or false based on parameters ! And, in the example given, parameters are not considered, so i don't think we should consider parameters if it is not given in question at all!

If they want to consider parameters, then they might ask full sentence, instead of single world like - void, int etc..
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Nitin,
Basic rule for overloading is that method name should remain same and parameter list should be different , there is no restriction on the return type of the overloaded method.
Here is extract from K&B book which tells the rules for overloaded methods


Overloaded methods must change the argument list.
Overloaded methods can change the return type.
Overloaded methods can change the access modifier.
Overloaded methods can declare new or broader checked exceptions.
A method can be overloaded in the same class or in a subclass.



Hope that helps ya
[ November 26, 2004: Message edited by: Jay Pawar ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two Mock Exam Q