MCQ Practice Single Best Answer Topic: Java Constructor and Methods

Q
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();
      }
}
which one is correct

Question ID
#2189
Subchapter
Java Constructor and Methods
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A two one one
  • B one one two
  • C one Exception
  • D Compilation Error
Correct Answer: D

Explanation

Compilation Error

Share This Question

Share this MCQ with your friends or study group.