ProgrammingHardProduct-company placement · Java

Which statement about the protected modifier is true in Java but NOT in C++?

  1. A. A protected member is accessible to any class in the same package, even one that is not a subclass
  2. B. A protected member is accessible in subclasses
  3. C. A protected member is inaccessible to unrelated classes in other packages or files
  4. D. A protected member can be overridden if it is a method

Correct answer: A. A protected member is accessible to any class in the same package, even one that is not a subclass

Java's protected = package access + subclass access. C++ has no packages: protected members are visible only to the class, its friends and derived classes.

More OOP with C++ and Java questions

Exams that ask this topic