what is invoking static methodsif a method or


What is Invoking static methods

If a method or field is declared static, you access it through using the class name rather than a reference to a particular example of the class. Thus instead of writing

Car c = new Car("New York", 89.7);
double maximumLegalSpeed = c.getSpeedLimit();
you just write
double maximumLegalSpeed = Car.getSpeedLimit();

There does not even have to be an example of a class in order to invoke a static method within the class.

Static methods might not call non-static methods or members of the same class directly. Rather they must specify that instance of the class they are referring to. Trying to call a non-static method or member is a very general compile time error. The specific error message generated through the javac compiler will look something such as this

Error: Can't make static reference to method void floorIt() in class Car.

Of course the names and signature will be changed to match the exact method and class.

 

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: what is invoking static methodsif a method or
Reference No:- TGS0284752

Expected delivery within 24 Hours