Constructors in Java
Constructors in Java
Q. What is constructor?
Ans: A constructor is a special function that is automatically called,
when the object is created of that class. It has the same name as that
of the class name and its primary job is to initialize the object to a legal
value for the class.
class Test
{
public Test()
{
}
Q. Why do we need a constructor as a class
member?
(i) Constructor has the same name as the class name, whereas
functions have different names from their class names.
i. Default Constructors.
ii. Parameterized Constructor.
iii. Copy Constructors.
Default or non-parameterized Constructor