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 Question about getter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about getter" Watch "Question about getter" New topic

Question about getter

Gina Ruffolo-Daniel

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

Joined: Jul 22, 2000
Posts: 9059
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".

"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.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Question about getter
It's not a secret anymore!