Non static method StartEngine() cannot be referenced from a static context?
GUIDE! When i try and compile this program i have the error information above
________________CODE__________________
training Motorcycle
open public static void main (String args)
Street bike m = new Motorcycle();
m.generate = “Yamaha RZ350”;
m.coloration = “yellow”;
Process.out.println(“Calling showAtts…”);
m.showAtts();
Process.out.println(“——–“);
Process.out.println(“Starting serps…”);
StartEngine(); //**********error here***********
Process.out.println(“——–“);
Process.out.println(“Calling showAtts…”);
m.showAtts();
Process.out.println(“——–“);
Process.out.println(“Starting serps…”);
m.StartEngine();
String make;
String color;
boolean engineState;
emptiness StartEngine()
in the event that (engineState == true)
Process.out.println(“The engine is already on.”);
else
engineState = legitimate;
Process.out.println(“The engine is already on”);
emptiness showAtts()
Process.out.println(“This may be a “+color+ ” “+make);
if(engineState == true)
Process.out.println(“The serps is on”);
else
Process.out.println(“The serps is off”);
StartEngine() may be a method that belongs on the “instance” of one’s class, my partner and i.e.you begin the engine on the particular Motorbike (“m”), NOT each at when.
m.StartEngine(); is the right way to invoke using this method.
this is the reason why you can’t access non-static functions coming from a static function(main as part of your program)
thus change perform prototype associated with function startEngine to
emptiness static startEngine()
//function body
Leave a Reply
You must be logged in to post a comment.