• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Two Mock Exam Q

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Forget Steve. Look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic