Reputation: 178
I have a question! I don`t know How can I retur the array? I want to use get and set.
TypeOfWater[] waters = returnTypes1();
public String[] getTypeOfWater()
{
return waters;//How can I rerutn array???
}
private static TypeOfWater[] returnTypes1()
{
TypeOfWater[] type = new TypeOfWater[4];
type[0] = new TypeOfWater();
type[0].name = "1)Fanta";
type[0].cost = 11;
type[1] = new TypeOfWater();
type[1].name = "2)Coca";
type[1].cost = 12;
type[2] = new TypeOfWater();
type[2].name = "3)Sprite";
type[2].cost = 14;
type[3] = new TypeOfWater();
type[3].name = "4)Orange juice";
type[3].cost = 22;
return type;
}
Please, help me. I am new at java programming.
Upvotes: 0
Views: 29
Reputation: 62
You should change
public String[] getTypeOfWater()
{
return waters;//How can I rerutn array???
}
for
public TypeOfWater[] getTypeOfWater()
{
return waters;//How can I rerutn array???
}
Upvotes: 1
Reputation: 91
The return data type of getTypeOfWater()
is incorrect. It's set to return String[]
when it should be returning TypeOfWater[]
getTypeOfWater()
is also a misleading function name if you're trying to return the array itself. If that's the case, the function should be renamed.
Upvotes: 0
Reputation: 316
The type of your return is not the good!
Water is TypeOfWater[] and your getTypeOfWater method return a String[]
So, try to change your String[] by a TypeOfWater[]
Upvotes: 0