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());
}
}
GetNumber()(which, incidentally, should be namedgetNumber()) is an instance method.This line doesn’t make sense:
You can’t call that method without an instance to call it on.