A

Admin • 828.03K Points
Coach

Q. What is the output of the program?
class MyClass{
MyClass(){
System.out.print("one");
}
public void myMethod(){
this();
System.out.print("two");
}
}

public class TestClass{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.myMethod();
}
}

  • (A) two one one
  • (B) one one two
  • (C) one Exception
  • (D) one Exception D. Compilation Error
  • Correct Answer - Option(D)
  • Views: 14
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
The code will result in a compilation error because in the method myMethod, the use of this() is incorrect.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.