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

Answer :

frknkrtrn

Answer:

Constructor issue

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.

Other Questions