Question: You are given the following code: public class AccessModifiers { public String publicString = I'm public; private String privateString = I'm private; protected String protectedString

You are given the following code:

public class AccessModifiers {

public String publicString = "I'm public";

private String privateString = "I'm private";

protected String protectedString = "I'm protected";

String defaultString = "I'm default";

public void printStrings() {

System.out.println(publicString);

System.out.println(privateString);

System.out.println(protectedString);

System.out.println(defaultString);

}

}

You are asked to add the following to test the code above:

Create another class called Main and add the main method. Display each access modifier and call the printStrings() method of the AccessModifiers class

Explain if there is any error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!