Definition:
Constructor is a Method of the class that has the same name as the class name in which it is.
We don't need to call the constructor instead whenever we make the object of the Class Constructor of
this class is automatically called.
In JAVA we use constructor as we use in C++ ( in Object Oriented Programming) . Following
example will demonstrate that how can we use Constructor.
Example Program:
public class Test {
Test() // Constructor
{
System.out.println("Faraz");
System.out.println("Awan");
}
public static void main(String[] args) {
new Test();
}
}
Constructor is a Method of the class that has the same name as the class name in which it is.
We don't need to call the constructor instead whenever we make the object of the Class Constructor of
this class is automatically called.
In JAVA we use constructor as we use in C++ ( in Object Oriented Programming) . Following
example will demonstrate that how can we use Constructor.
Example Program:
public class Test {
Test() // Constructor
{
System.out.println("Faraz");
System.out.println("Awan");
}
public static void main(String[] args) {
new Test();
}
}
No comments:
Post a Comment