Leave a Reply 5

Your email address will not be published. Required fields are marked *


ARJIT GAUTAM

ARJIT GAUTAM

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.

obrain

obrain

A. Compilation fails due to an error at line n3

nisha

nisha

What is the question?

Ashutosh

Ashutosh

Where is question ?

renko

renko

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);
}
}