Question 5 Consider the following code snippet: public class Inventory implement
ID: 3685545 • Letter: Q
Question
Question 5
Consider the following code snippet:
public class Inventory implements Measurable
{
private int onHandCount;
. . .
public double getMeasure();
{
return onHandCount;
}
}
Why is it necessary to declare getMeasure as public?
All methods in a class are not public by default.
All methods in an interface are private by default.
It is necessary only to allow other classes to use this method.
It is not necessary to declare this method as public.
All methods in a class are not public by default.
All methods in an interface are private by default.
It is necessary only to allow other classes to use this method.
It is not necessary to declare this method as public.
Explanation / Answer
By using this instance variable onHandCount the value is stored in heap. to get this value and method from any class we are using as public.
public scope is visible everywhere.
Note : the instance variable onHandCount is declared with private
private has scope only with in the class.
we have to return the value onHandCount by using public.
so the option is "It is necessary only to allow other classes to use this method"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.