Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About return type in JAVA

 
vinay kalal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch .

Next time use code tag, while posting your code. so that, it can be easy to read.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites
http://www.daniweb.com/forums/thread312546.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic