Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: constructor overloading

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default constructor overloading

    class ConstructorOverloading
    {
    int a, b, c;
     
    ConstructorOverloading(int x, int y, int z)
    {
    a=x;
    b=y;
    c=z;
    }
    public int cubeArea()
    {
    int d=a*b*c;
    return d;
    }
     
    ConstructorOverloading(int x, int y)
    {
    a=x;
    b=y;
    }
    public int rectangleArea()
    {
    int d=a*b;
    return d;
    }
     
    }
    class TestOverloadedConstructor
    {
    public static void main(String args[])
    {
     
    ConstructorOverloading test1=new ConstructorOverloading(3,5);
    System.out.println("Area of rectangle is : " +test1.rectangleArea());
     
    ConstructorOverloading test2=new ConstructorOverloading(3,5,7);
    System.out.println("Area of cube is : " +test2.cubeArea());
     
    }
     
    }
    Last edited by helloworld922; August 13th, 2013 at 01:12 AM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: constructor overloading

    please use [code] tags.

    What is your question?

Similar Threads

  1. Overloading a method
    By Lahoree in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 15th, 2013, 12:46 PM
  2. which class has a default constructor? (Req. guidance on constructor)
    By DragBall in forum Java Theory & Questions
    Replies: 1
    Last Post: June 27th, 2012, 05:42 PM
  3. Overloading Method
    By Tohtekcop in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 16th, 2012, 03:28 PM
  4. Method Overloading - Doubt
    By vidya lakshman in forum Java Theory & Questions
    Replies: 2
    Last Post: January 31st, 2011, 09:32 AM
  5. Overloading vs Overriding
    By nickypass in forum Java Theory & Questions
    Replies: 1
    Last Post: October 17th, 2010, 02:53 AM

Tags for this Thread