aspose file tools*
The moose likes Beginning Java and the fly likes About return type in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About return type in JAVA" Watch "About return type in JAVA" New topic
Author

About return type in JAVA

vinay kalal
Greenhorn

Joined: Sep 19, 2010
Posts: 9
I am doing some problems regarding Return type in java.I am facing some problems. could any help please.


1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; } // what mean 'return this' here or return super mean
4. }
5. class Flower extends Plant {
6. ( / insert code here. I have four options A to D. A,C,D are correct here but don't know why? Anyone explain.)
A. Flower getType() { return this; }
B. String getType() { return "this"; }
C. Plant getType() { return this; }
D. Tulip getType() { return new Tulip(); }
7. }
8. class Tulip extends Flower { }
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

I Assume you are expecting explanation about this and super.

this - refers currently executing object, you can use with return
super - refers super class object, you cant use with return directly like return super;

hth
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch .

Next time use code tag, while posting your code. so that, it can be easy to read.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4530
    
    5

BeForthrightWhenCrossPostingToOtherSites
http://www.daniweb.com/forums/thread312546.html


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About return type in JAVA