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);

  1. Rectangle r; //reference variable is created

  2. R=new Rectangle(); //The object has memory allocated, and reference is kept in the reference variable.

  3. 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);
    } 
}