Why does my code doesn't work?


#1



class Coffee extends Beverage {
    
    public Coffee() {

    }
    
    public void addSugar(int cubes) {

        System.out.println("You added " + cubes + " sugar cubes.");

    }

    public static void main(String[] args) {
    
    Coffee myOrder = new Coffee();
    myOrder.addSugar(2);
    myOrder.isFull();

    }
}


#2

The code looks ok. Do you get any errors? Check Beverage class, maybe there is some kind of problem but if there any kind of problem in will be only on this line: myOrder.isFull(); for method isFull();


#3

I am going to have to agree with perk-one, the code looks fine.
Also perk-one is correct in asking, did you get an error?


#4

No. There is no such error but it says the problem is that the object "myOrder" is not created inside the main method.
I have a doubt..do i have to create the object in class "coffee" or class "beverage" ?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.