Given the code fragments:
Which modification enables the code to compile?
A.
B.
C.
D.
Given the code fragments:
Which modification enables the code to compile?
A.
B.
C.
D.
To compile the code provided, you need to ensure all classes are correctly imported in their respective packages. In `B.java`, `class B` needs to use `class A` from package `p1`, and in `C.java`, `class C` needs to use `class A` from package `p1` and `class B` from package `p1.p2`. Therefore, the correct modification to enable the code to compile is to replace: Line n1 in `B.java` with `import p1.A;` to import `class A`; Line n2 in `C.java` with `import p1.A; import p1.p2.B;` to import both `class A` from `p1` and `class B` from `p1.p2`.
The answer is the letter C. You don't need to explain much because the other alternatives are very wrong. But it's worth remembering that when we use * we import all the classes in the package but we don't import the classes of the sub-packages. Having this concept the others are wrong
good tip
I do not understand p1. p2.B ?? I only see p2.B or p2.*
correct answer A !!!!!! import p1.*; import p1.p2.*;
nah man, read it again, class C need 2 imports in answer A it only mentions 'import p1.p2.*;' in class C, which will give problem in detecting class A
C : A is needed in class B; A and B are needed in class C
Answer is C, agree
The answer is C