Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote