Can any one help? I KNOW it’s a real basic one, but it has me stumped.
My class has a superclass where I need to pass name, cost and size. The constructor in the subclass is as follows:-
/**
* Constructor for objects of class MilkBeverage, including variables of Super class (name,cost and size)
*/
public MilkBeverage(String milkName,float milkCost,char milkSize,String milkFlavour)
{
super(milkName,milkCost,milkSize);
flavour = milkFlavour;
name = "milkshake";
cost = milkCost;
size = milkSize;
option = 0;
}
When I initiate a new object I’m using:-
/**
* Main method of the MilkBeverage
*
* @param none
* @return none
*/
public static void main(String[] args)
{
MilkBeverage wotDrink = new MilkBeverage(name,cost,size,flavour); ß-------- Error here
wotDrink.director();
}
/**
The error I get on compilation is non-static variable name cannot be referenced from a static context.
I realise this, but if I leave the new MilkBeverage empty, I then get an error saying cannot find symbol – constructor MilkBeverage()
Can someone help out and let me know how this SHOULD be written?
Many thanks
Tags: