This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question about getter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about getter" Watch "Question about getter" New topic
Author

Question about getter

Gina Ruffolo-Daniel
Greenhorn

Joined: Oct 01, 2005
Posts: 19
I am a newbie to OO programming and programming in general. My question relates to the getter method.



How come I have to specify return of String sometimes and other times I don't?

Thank you in advance
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
public Delivery(String y, String m, String d, String w, String c)

public String getDelivery()

How come I have to specify return of String sometimes and other times I don't?


The first line is a constructor. The second line is a method. A constructor will never return anything, not even void. All methods must return something, even if that something is "void".


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As Marilyn points out, you first need to understand the difference between a constructor and a regular method. Once you figure out that much, then you need to work what the return type means. All methods have a return type. (Note that constructors are not methods.) If you still need help, please let me know and I will be glad to explain further.

Layne


Java API Documentation
The Java Tutorial
 
wood burning stoves
 
subject: Question about getter
 
Similar Threads
DateRec
Date Class Problems
help creating mutator
New to Java - i need help please!
Creation and usage of a class