Which change will enable the code to compile?

Given: Which change will enable the code to compile?

Given: Which change will enable the code to compile?

A.
Adding the public modifier to the declaration of method1 at line n1

B.
Removing the public modifier from the definition of method1 at line n2

C.
Changing the private modifier on the declaration of method 2 public at line n3

D.
Changing the line n4 DoClass doi = new DoClass ( );

Explanation:



Leave a Reply 4

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


Kurt

Kurt

The question of my test said: Which TWO change will enable the code to compile?
The correct answer for my test is C & D

renko

renko

Indeed D and D:

Code:
package p1;

public interface DoInterface {
void method1(int n1); // line n1
}
package p3;
import p1.DoInterface;

public class DoClass implements DoInterface {
public DoClass(int p1) { }
public void method1(int p1) { } // line n2
public void method2(int p1) { } // line n3

}
import p1.DoInterface;
import p3.DoClass;

import p1.DoInterface;
import p3.DoClass;

public class Test {

public static void main(String[] args) {
DoClass doi= new DoClass(1000); // line n4
doi.method1(100);
doi.method2(100);
System.out.println(“Answer C and D”);
}

}
Output:
Answer C and D