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

3 comments:

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

      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

ShareThis