The keyword static when applied to a field means what:
There is a copy of the field for each class object.
The field may be accessed only by the constructor of the class.
Only one copy of the field in memory
The field is subject to garbage collection.
What does it mean for a class method to be static?
It means the method is private.
It means the method is public.
It means the method can be called on the class only (ie. ClassName.method()).
It means the method can be called on the class as well as on objects of that class (ie. ClassName.method() and object.method()). However, note that it is convention to call static methods on the Class name, not on objects.
The Java Math class is a collection of static methods, one of which is sqrt(number). It accepts a numeric argument and returns the square root of the argument as a double. What would be the correct way to invoke sqrt to compute the square root of 25?
double ans = sqrt(25);
double ans = Math.sqrt(25);
double ans = static.sqrt(25);
double ans = static Math.sqrt(25);
1)
Keyword static means that for every object the value is constant.
So here correct answer is There is copy of value for each class obeject.
-------
2)
When we declare a method as static, It means the method can be called using a class name as well as on objects of that class.
For example if the class name is : App
And of the method name is doSomething() which is declared as static.
Then we call that method as App.doSomething() or
We can create an object and then we can call that method.
For example:
App a = new App();
a.doSomething();
-------
3)
Here the correct answer is :
double ans = Math.sqrt(25);
Explanation:
Math.sqrt() is a static method that is present inside the jav.lang package.
We can call a static method directly.
Get Answers For Free
Most questions answered within 1 hours.