3.1: Program
on Default Constructor.
Class
Default
{
int length,width;
Default()
{
Length=5;
Width=5;
}
int Area()
{
Return(length*width);
}
}
Class
DefaultMain
{
Public static void main(String
s[])
{
Default obj=new
Default();
Int
result=obj.Area();
System.out.println(“Area=”+result);
}
}
Output
Area=25
3.2. Program
on Parameterized Constructor.
Class
Parameter
{
Int length, width;
Parameter(int x, int y)
{
Length=x;
Width=y;
}
Int Area()
{
Return(length*width);
}
}
Class
ParameterMain
{
Public static void main(String
s[])
{
Parameter
obj=new Parameter(10,20);
Int
result=obj.Area();
System.out.println(“Area=”+result);
}
}
Output is
Area = 200
Science Tutor | Smart Study Anytime Anywhere !!
0 Comments
Please share your opinions and suggestions with us.