What is constructor ?

What is constructor ?

Constructors are the special member functions which have 
the same name as the class name. The most important 
thing is that they don\'t hava return type. Constructors 
may be overloaded. If you don\'t provide a constructor 
for the class, the compiler will supply the defualt one. 
Constructors can have any of the access modifiers.

Example:

public class MyClass{
int i;
int j;
public MyClass(){}
protected MyClass(int i){}
private MyClass(int i,int j){}
}

By:Jalees
Date:2012-01-09 00:00:00

Constructors are the special member functions which have 
the same name as the class name. The most important 
thing is that they don\'t hava return type. Constructors 
may be overloaded. If you don\'t provide a constructor 
for the class, the compiler will supply the defualt one. 
Constructors can have any of the access modifiers.

Example:

public class MyClass{
int i;
int j;
public MyClass(){}
protected MyClass(int i){}
private MyClass(int i,int j){}
}

By:Sumit Tripathi
Date:2019-05-15 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher