17.7k views
4 votes
Analyze the following code:

public class Test {
public static void main(String[] args) {
A a = new A();
a.print();
}
}

class A {
String s;

A(String newS) {
s = newS;
}

void print() {
System.out.println(s);
}
}

User Sean K
by
6.0k points

1 Answer

0 votes

Answer:

Constructor issue

Step-by-step explanation:

When you look at the Class A, the constructor takes one argument as a parameter, a String.

A(String newS) {

s = newS;

}

However, in the main, the constructor does not take any argument as a parameter.

A a = new A();

That's why the code does not compile.

User Inakiabt
by
6.4k points