Q:

Java - Constructor Demo

0

This Program is used to demonstrate the Constructor concept.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

class test4

  {

    int l;

    int b;



    test4() // default constructor

     {        l=1;

               b=2;   

    }

    test4(int tl) // function name is same as class name

     {         l=tl;

                b=4;    

     }

     test4(int tl,int tb) // class name same as function  name with different parameter

      {         l=tl;

                 b=tb;    

      }

          void display()

        {

            System.out.println("\n");         

            System.out.println("Length of the rectangle = "+l);

            System.out.println("Breadth of the rectangle = "+b);

        }

          public static void main(String arg[])

        {

             test4 r1=new test4();

             r1.display();

             test4 r2=new test4(6);

             r2.display();

             test4 r3=new test4(10,20);

             r3.display();

        } 

  }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now