File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 5115


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
It's not a secret anymore!