Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about getter

 
Gina Ruffolo-Daniel
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic