Go to Top

Tuesday, 25 October 2011

Constructor Overloading

Demonstration of constructor overloading.

Java Program :

class const_overload
{
    int a,b,c;
    const_overload()
        {
            a=12;
            b=60;
            c=a+b;
        }
    const_overload(int p,int q)
        {
            a=p;
            b=q;
            c=a+b;
        }
    void display()
        {
            System.out.print("Value : "+c);
        }
}

5 comments:

  1. Replies
    1. IT IS ONE OF THE PRINCIPLE OF OOP.

      Delete
    2. Constructor overloading enables to create an object of class and constructor is used to initialise data members to perform other complex tasks..
      ~hope dis will help u

      Delete
  2. Pls make program for...
    Class name-result
    Member function - name,rollno, sub1&sub2
    Constructor to initialize
    result(String, int)
    Input(int,int,int)
    Double()
    Char grade(double)
    And display() method

    ReplyDelete
  3. some more examplese

    ReplyDelete

ShareThis