Java · Question 19 · Easy

Which access modifier makes a class member accessible only within the class in which it is declared?

  1. default (no modifier)
  2. public
  3. protected
  4. private
Answer and explanation

Answer: D. private

Explanation: private members are visible only inside their own class. Default access allows the same package, protected adds subclasses, and public allows everyone.

Previous: What will be the output of the following Java program? · Next: What will be the output of the following Java program?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge