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.
Report an error
The more specific you are, the faster it gets fixed. A source beats an opinion.
Prefer email? [email protected]
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.
Discussion
Stuck on an option, or know a faster way to get there? Ask or explain it here.
No comments yet. Be the first to explain this one.
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.
More Software Design and Architecture questions
What is the output for the below code ? public class Test{public static void main(String[] args){int i = 010; int j = 07;System.out.println(i); System.out.println(j); } } ?
Size of int in Java is_________________?
Which of the following command is used to compile the Java program ?
JIT meaning ?
Runnable is_______________?
The object is created with "new" keyword ?