JAVA CONSTRUCTORS

//All constructor method and overloading programs….I think you help from here

public class constructors //class name declare here
{
String name; //String type variable declare
int i,j; //int type variable declare
constructors() //default constructor method because it has “no return type and “no parameter” and method name is “same the class name”
{
System.out.println(“\nDefault constructor method.”);
}
constructors(String name) //normal constructor method because it has a parameter and method name is the same of the class name
{
System.out.println(“\nNormal constructor method.”);
}


void show() //”normal method” without parameter because “method name is not same the class name”
{
System.out.println(“\nNormal method without parameter”);
}
void show(int i) //”normal method” with parameter because “method name is not same the class name” ……and here happen Overloading
{
System.out.println(“\nNormal method with parameter.”);
}
constructors(int j) //normal constructor method…….and …here also happen overloading
{
System.out.print(“\nIt is also a normal constructor method”);
System.out.println(” and it has a int type variable”);
}
public static void main(String args[])
{
System.out.println(“It is a program where has all constructor method and also happen overloading”);
constructors ob = new constructors(); //creating object of default constructor method
constructors ob2 = new constructors(” Rana”); //another object creating of normal constructor method
ob.show(); //creating object for normal method
ob.show(4);
constructors ob3 = new constructors(3);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *