This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About return type in JAVA" Watch "About return type in JAVA" New topic

About return type in JAVA

vinay kalal

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;

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

Joined: May 03, 2008
Posts: 4523


luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: About return type in JAVA
Similar Threads
doubt -chapter 2 K& B -self test -q no 8
K&B doubt
Question from the scjp book
Return type
overridding and co-variant returns query