• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

About return type in JAVA  RSS feed

 
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 { }
 
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.
 
Bartender
Posts: 5167
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
Boost this thread!