Multiple choice

Read the following statements and choose the correct option.

P) Variable or function declared in a class as private cannot be accessed outside the class even though the class is inherited by another class. Q) Public variables or functions of a class can be accessed to any class. R) When a class is declared as Static , it doesn't need an instance to access it members. S) When a member of class is declared as protected access modifier, then it can accessed by its child classes.

  1. All the statements P, Q, R and S are true.

  2. Only P, Q and R are true.

  3. Only S is true.

  4. Only R and S are true.

  5. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

 P) Private access modifier restricts the access of the member to the outside classes. Q) Public members can be accessed by any class. R) Static indicates that JVM creates objects to static items without any instance, hence object creation is not necessary for static items. S) Protected members of a class can be accessed only its child classes and cannot be accessed by other classes. P,Q,R and S are true.