aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt about question 10 in chapter 2 in K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt about question 10 in chapter 2 in K&B" Watch "doubt about question 10 in chapter 2 in K&B" New topic
Author

doubt about question 10 in chapter 2 in K&B

Debolina Ray
Greenhorn

Joined: Jan 29, 2008
Posts: 4
In question 10 (Page 162 ) why is 'C' not a valid answer. I thought everything in inherited from Object. So why Object won't be a valid return type.
Thanks for any help in advance.
Debolina Ray
Greenhorn

Joined: Jan 29, 2008
Posts: 4
found the answer. Has to be a subtype of the declared return type.
Arjun Cheng
Greenhorn

Joined: Jan 08, 2008
Posts: 13
Hi, I don't have same book. but I think to return an object you just can return a same type object or which is inheritance of it. not a super class.

class Sp(){}
class Su extends Sp {

sp getSp (){ return new Su();} // This is Legal
// su getSu () { return new Sp(); } //this is illegal.
// su getSu () { return new Object(); } //this is illegal too.
}
Jart Bo
Ranch Hand

Joined: Oct 22, 2007
Posts: 144
Originally posted by Debolina Ray:

In question 10 (Page 162 ) why is 'C' not a valid answer. I thought everything in inherited from Object. So why Object won't be a valid return type.
Thanks for any help in advance.



Hi Debolina,

The question seems to be asking for legal overloading and overriding. C is not a legal overload because the argument did not change. In addition, it's not a legal override because the return type is not a subclass of the return type of the method being overriden.


SCJP, SCWCD
Mikael T Andersson
Greenhorn

Joined: Oct 13, 2008
Posts: 3
Originally posted by Debolina Ray:
In question 10 (Page 162 ) why is 'C' not a valid answer. I thought everything in inherited from Object. So why Object won't be a valid return type.
Thanks for any help in advance.


Hi! I don't understand why C isn't a valid answer. As I understand it, A is a valid answer since SCJP is-a Programmer. But every class is-a Object so why isn't C a correct anser?
The question is question 10 page 162 in K&Bs book SCJP 5 study book. Could someone explain, im sure it isn't very difficult but I don't understand.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Mikael don't post on such old threads. If you have a doubt, start a new thread...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11419
    
  16

also, please remember not everyone has, or has easy access to, the book. It's legal to post the full question, as long as you cite the source. many folks will look at this and say "well, i'd LIKE to help, but since I have no idea what the questions says, i'll just move along to something else."


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt about question 10 in chapter 2 in K&B