Analyze the following code class Test public static void mai

Analyze the following code: class Test {public static void main(String[] rags) {A a = new A(\"test\"); a. print();}} class A {String s; A{String s) {this. s = s;} void print(String s) {System. out. println(s);} The program has a compilation error because class A does not have the right constructor. The program has a compilation error because the print() method in class A is not public. The program has a compilation error because the print() method in class A requires a String parameter. The program runs fine and prints Test.

Solution

Answer:- (c)

Explanation:- In the main method of Class Test, we have defined a object \'a\' of Type \'A\' and tried to call \'print\' method on \'a\'. But there is no parameter passed while calling the \'print\' method as expected by \'print\' method. So,it gives a compilation error.

 Analyze the following code: class Test {public static void main(String[] rags) {A a = new A(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site