Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This problem tests your knowledge of visibility modifiers (so you should focus o

ID: 3721660 • Letter: T

Question

This problem tests your knowledge of visibility modifiers (so you should focus on the accessibility). suppose that we are the following code about class A and B that are located in different packages as shown in the following diagram:

Package p1:

public class A {

? int i;

? void m () {

....

}

}

package p2;

public class B extends A {

public void m 1(String [ ] args) {

System.out.println(i);

m();

}

}

Using your knowledge on the visibilty modifieris, answer the following three sub questions.

A. If the question marks are replaced by blanks (default visibilty), can Class B be compiled?

Answer:

B. If the question marks are replaced by private, can Class B be compiled?

Answer:

C. If the question marks are replaced by protected, can Class B be compiled?

Answer:

Package p1:

public class A {

? int i;

? void m () {

....

}

}

Explanation / Answer

A. If the question marks are replaced by blanks (default visibilty), can Class B be compiled?

Answer: Yes. It will compile

B. If the question marks are replaced by private, can Class B be compiled?

Answer: No. It will not compile

C. If the question marks are replaced by protected, can Class B be compiled?

Answer: Yes. It will compile

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote