1

I am getting a error saying that cannot make a static reference to the non-static method GetNUmber() from the type Vehicle.I don't really understand what's happening. Please help!

public class Vehicle
{

    private int VehicleNumber;




public void SetNumber (int N){

    VehicleNumber = N;

}

public  int GetNumber (){

    return VehicleNumber;

}


public static void main (String args[]){

    Vehicle Maxda = new Vehicle();
    Maxda.SetNumber(23423);
    System.out.println("Vehicle Maxda number is " + GetNumber());


}   
}   
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964

1 Answers1

4

GetNumber() (which, incidentally, should be named getNumber()) is an instance method.

This line doesn't make sense:

    System.out.println("Vehicle Maxda number is " + GetNumber());

You can't call that method without an instance to call it on.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964