aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp question from the 2nd chapter 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 "scjp question from the 2nd chapter" Watch "scjp question from the 2nd chapter" New topic
Author

scjp question from the 2nd chapter

nikunj thakur
Ranch Hand

Joined: Sep 23, 2007
Posts: 47
1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower {}

Which statement(s), inserted at line 6, will compile? (Choose all that apply.)

Flower getType() { return this; }

String getType() { return "this"; }

Plant getType() { return this; }

Tulip getType() { return new Tulip() ;}


In the above example the answers are 1st,3rd & 4th line, but in the 4th line return why can't i write return this instead of new Tulip().
[ October 24, 2007: Message edited by: nikunj thakur ]
Prahlad Joshi
Ranch Hand

Joined: Apr 21, 2007
Posts: 44
return this will return a reference to flower that can not be assignd to Tulip
Prahlad Joshi
Ranch Hand

Joined: Apr 21, 2007
Posts: 44
return this will return a reference to flower that can not be assigned to Tulip
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scjp question from the 2nd chapter