0

Hi,

Can anyone tell me what is wrong with this code? It seems to be throwing me some error: non-static method getName() cannot be referenced from a static context.

 public void printOrders()
    {
        for(Order filename: Orders) {

         System.out.println("Name: " + Order.getName()); 
         System.out.println("Quantity: " + Order.getQuantity());

        }
    }
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by KRUX17
0

Order is the class name. YOu use it to refer to static variables and methods of the class. If those are instance (non-static) methods then you need to call them with an instance of the class, eg filename

0

Oh, thanks that was a silly mistake. Just wondering what are static variables?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.