Page 301 - CA_Blue( J )_Class10
P. 301

7  {
                   8      System.out.println("Integer : " + a);

                   9      System.out.println("Double : "+ b);
                  10      System.out.println("String : "+ s);

                  11  }
                  12  public static void main()

                  13  {
                  14      default_cons ob = new default_cons();

                  15      ob.print();
                  16  }

                  17  }

                 You will get the following output:











                 12.2.2 Parameterised Constructor
                 A parameterised constructor is a type of constructor with parameters and statements inside its body. Number of
                 parameters may be different depending on the number of instance variables. For example:

                   1  import java.util.*;
                   2  class rectangle1

                   3  {
                   4      int length,breadth,area, perimeter;

                   5      rectangle1(int l, int b)
                   6      {

                   7         length=l;
                   8         breadth=b;

                   9      }
                  10      void cal()

                  11      {
                  12         area = length * breadth;

                  13          perimeter = 2*(length+breadth);
                  14      }

                  15      void display ()



                                                                                                                       299
                                                                                                         Constructors  299
   296   297   298   299   300   301   302   303   304   305   306