Forums Register Login

Question about getter

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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".
+Pie Number of slices to send: Send
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
ice is for people that are not already cool. Chill with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 644 times.
Similar Threads
help creating mutator
Creation and usage of a class
New to Java - i need help please!
Date Class Problems
DateRec
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:55:15.