Question: Analyze the following code: public class Test { public static void main(String[] args) { A a = new A(); a.print(); } } class A {
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 s) { this.s = s; }
void print() { System.out.println(s); } }
Question 4 options:
|
| The program has a compile error because class A is not a public class. |
|
| The program would compile and run if you change A a = new A() to A a = new A("5"). |
|
| The program compiles and runs fine and prints nothing. |
|
| The program has a compile error because class A does not have a default constructor. |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
