Suppose a class has public visibility. In this class we define a protected method. Which of the following statements is correct ?
Correct answer: D. This method is accessible from within the class itself and from within all classes defined in the same package as the class itself.
- A. From within protected methods you do not have access to public methods.
- B. This method is only accessible from inside the class itself and from inside all subclasses.
- C. In a class, you cannot declare methods with a lower visibility than the visibility of the class in which it is defined.
- D. This method is accessible from within the class itself and from within all classes defined in the same package as the class itself.
Explanation
A protected method is accessible within its own class and by classes in the same package, as stated in option d. It is also accessible to subclasses, but option b incorrectly uses “only” and omits package access.
Last updated
Practise Software Design and Architecture
493 free Software Design and Architecture MCQs from Software Engineering, each with the correct answer and an explanation. Unlimited attempts, no account needed.
Exams that ask Software Engineering questions like this
Software Engineering is on this paper prepared for on TestUstad, and all of them draw the same bank, so this question is worth knowing for it.
Related questions
If you were to create client/server applications, which model would you go for ?
Which one of the following is not an application of embedded software product ?
__________________ allows us to infer that different members of classes have some common characteristics ?
The UML supports event-based modeling using _______________ diagrams?
Which model in system modelling depicts the static nature of the system ?