πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (D) one Exception D. Compilation Error

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

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
98
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Shiva Ram
Publisher
πŸ“ˆ
99%
Success Rate