Parameterized Constructor
Author: Ravi Poswal
Those constructors have the arguments called parameter constructors,s, i.e., a fixed number of arguments to be passed. Example:-
Rectangle r=new Rectangle(5,7);
-
Rectangle r; //reference variable is created
-
R=new Rectangle(); //The object has memory allocated, and reference is kept in the reference variable.
-
r.Rectangle (5,6); //construct is invoked
Code Example
class Rectangle
{
Rectangle(int x)
{
System.out.println("parameterized constructor "+x);
}
public static void main(String arg[])
{
Rectangle e=new Rectangle(34);
}
}
RANREV INFOTECH