Given: What is the result?
A.
Compilation fails due to an error at line n3
B.
100 210
C.
Compilation fails due to an error in line n1
D.
Compilation fails due to an error at line n2
Explanation:
Given: What is the result?
Given: What is the result?
A.
Compilation fails due to an error at line n3
B.
100 210
C.
Compilation fails due to an error in line n1
D.
Compilation fails due to an error at line n2
Explanation:
Answer is A. Code will not compile and show compilation error at line n3.
Beacause DoClass constructor of class DoClass has a default access specifier and we are instantiating the DoClass in another package p3. So code wont compile.
A. Compilation fails due to an error at line n3
What is the question?
Where is question ?
Code question:
package p1;
public interface DoInterface {
//public void m1(int n); //line n1
public void m2(int n);
}
package p2;
import p1.*;
import p3.*;
public class Test {
public static void main(String[] args) {
DoInterface doi = new DoClass(); //line n3
doi.method1(100);
doi.method2(200);
}
}
package p3;
import p1.DoInterface;
public class DoClass implements DoInterface {
int x1, x2;
public DoClass() {
this.x1 = 0;
this.x2 = 10;
}
public void m1(int p1) { // line 2
x1 += p1;
System.out.println(x1);
}
public void m2(int p1) {
x2 += p1;
System.out.println(x2);
}
}