Recall & Review
beginner
What does the
protected access modifier mean in Java?It means the member is accessible within its own package and by subclasses even if they are in different packages.
touch_appClick to reveal answer
beginner
Can a
protected member be accessed by classes in a different package that are not subclasses?No, only subclasses or classes in the same package can access
protected members.touch_appClick to reveal answer
intermediate
Which of these access modifiers allows access only within the same package and subclasses outside the package?
public, private, protected, defaultprotected allows access within the same package and to subclasses outside the package.touch_appClick to reveal answer
beginner
Example: If class
Animal has a protected method makeSound(), can a subclass Dog in a different package call makeSound()?Yes, because
Dog is a subclass, it can access the protected method even if it is in a different package.touch_appClick to reveal answer
beginner
True or False: <code>protected</code> members are accessible from any class in the Java program.False.
protected members are not accessible from all classes, only from the same package or subclasses.touch_appClick to reveal answer
Which classes can access a
protected member in Java?If a class
Car has a protected field, can a non-subclass in a different package access it?What is the default access level if no modifier is specified in Java?
Which access modifier allows the widest access?
Can a subclass in a different package access a
protected member of its superclass?Explain in your own words what the
protected access modifier does in Java.Describe a real-life example that helps you remember when to use
protected in Java.