Answers for ""this" : to invoke current class constructor"

0

"this" : to invoke current class constructor

The this() constructor call can be used to invoke the current class constructor. It is used to reuse the constructor. In other words, it is used for constructor chaining. 

Example 
class A{  
A(){System.out.println("hello a");}  
A(int x){  
this();  // Current class constructor is called.
System.out.println(x);  
}  
}  
class TestThis5{  
public static void main(String args[]){  
A a=new A(10);  
}}
Posted by: Guest on August-31-2021

Code answers related to ""this" : to invoke current class constructor"

Browse Popular Code Answers by Language