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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.