Page 307 - CA_Blue( J )_Class10
P. 307

32      }
                  33      shape(double r)

                  34      {

                  35          radius = r;
                              double area=22.0/7.0*radius*radius;
                  36          System.out.println("It is a circle with area :"+(22.0/7.0*radius*radius));
                  37          System.out.println("Side : " + side);
                  38          System.out.println("Length : " + length + "breadth : "+ breadth);

                  39          System.out.println("--------------------------------------------------");
                  40      }

                  41      public static void main()
                  42      {

                  43
                  44          shape ob1=new shape(5);

                  45
                  46

                  47          shape ob2=new shape(5,2);
                  48

                  49
                  50          shape ob3=new shape();

                  51
                  52

                  53          shape ob4=new shape(4.6);
                  54    }

                  55  }

                 Explanation:
                 1.  ob1 is created by invoking the constructor where the area of the square is calculated as "s" is initialized to "side".
                    And rest are initialized to their default initial values.
                 2.  ob2 is created by invoking the constructor where the area of the rectangle is calculated as "l" is initialized to
                    "length" and "b" is initialized to "breadth". And rest are initialized to their default initial values.
                 3.  ob3 is created by invoking the constructor where all the instance variables are initialized to their default initial
                    values.
                 4.  ob4 is created by invoking the constructor where the area of the circle is calculated as "r" is initialized to "radius".
                    And rest are initialized to their default initial values.









                                                                                                                       305
                                                                                                         Constructors  305
   302   303   304   305   306   307   308   309   310   311   312