Java OCA OCP Practice Question 460

Question

How can you declare 'i' so that it is not visible outside the package test.

package test; 
public class Test{ 
   XXX int i; 
   /*  irrelevant code */ 
} 

Select 2 options 
  • A. private
  • B. public
  • C. protected
  • D. No access modifier
  • E. friend


Correct Options are  : A D

Note

A. is correct.

Note that the question does not require that 'x' should be accessible from test package.

So private is fine.

B. is wrong.

Marking it public will make it accessible from all classes in all packages.

C. is wrong.

It will make it available to a subclass even if the subclass is in a different package.

E. is wrong.

There is no such modifier in Java.




PreviousNext

Related