Google News
logo
Java Constructor - Interview Questions
How many types of Constructors are in Java?
There are two types of constructors in Java :
 
* Default Constructor (Non-parameterized Constructor)
* Parameterized Constructor

The syntax for the default constructor is as follows :
 
<class name>() {}  

Example :
Employee()  
{  
//some code  
} 
 
The syntax for the parameterized constructor is as follows :
 
<class name>(arg1, arg2) {}  

Example :
Employee(int i, String n)  
{      
    id = i;    
    name = n;    
} ​

 

 
Advertisement