Recall & Review
beginner
What does the
public access modifier mean in Java?The <code>public</code> access modifier means the class, method, or variable can be accessed from any other class in any package.touch_appClick to reveal answer
beginner
Can a
public method be accessed from a different package?Yes, a
public method can be accessed from any other package in the Java program.touch_appClick to reveal answer
intermediate
Which of these is true about
public classes in Java?A <code>public</code> class can be accessed from any other class in any package, and the file name must match the public class name.touch_appClick to reveal answer
beginner
Example: What is the access level of this method?
public void greet() { System.out.println("Hello"); }The method <code>greet()</code> is <code>public</code>, so it can be called from any other class anywhere in the program.touch_appClick to reveal answer
intermediate
What happens if you do not specify any access modifier in Java?
If no access modifier is specified, the default is package-private, meaning the member is accessible only within the same package, unlike
public which allows access from anywhere.touch_appClick to reveal answer
What does the
public access modifier allow?If a class is declared
public, where can it be accessed?What must match the file name in Java?
Which access modifier restricts access to the same package only?
Can a
public method be accessed from a class in a different package?Explain what the
public access modifier does in Java and give an example.Describe the difference between
public and default (no modifier) access in Java.