Constructor Programs:
class Constr
{
int i;
float f;
long l;
double d;
char c;
String s;
Constr() // Constructor
{
i=0;
f=0.0f;
l=0;
d=0.0d;
c=' ';
s="";
System.out.println("Constructor called");
}
public static void main()
{
Constr ob=new Constr();
}
}
//Types of Constructor
import java.util.*;
class Constructor1
{
int i;
float f;
long l;
double d;
char c;
String s;
Constructor1() //Default Constructor
{
i=0;
f=0.0f;
l=0;
d=0.0d;
c=' ';
s="";
}
Constructor1(int a,int b) //Parameterized Constructor
{
System.out.println(a+" "+b);
}
public static void main()
{
Scanner sc=new Scanner(System.in);
int a1,b1;
Constructor1 ob=new Constructor1();
System.out.print("Enter First Number ");
a1=sc.nextInt();
System.out.print("Enter Second Number ");
b1=sc.nextInt();
Constructor1 obj=new Constructor1(a1,b1);
}
}