Skip to content

Java Constructor- overloading

Simple java program under topic of CONSTRUCTORS
This program includes overloading constructors
Code shared by Umang Mistry (Vissanji Academy) X B

Code:

/**
 * this is a simple java program under sub topic of CONSTRUCTORS
 * this program includes overloading constructors
 */
public class cons
{
    int a, b, c;//initializing global variable ***
    public cons ()//creating constructors ***
    {
        a = 0;
        b = 0;
        c = 0;
    }
    public cons(int a1, int b1, int c1)//creating constructors ***
    {
    a = a1;
    b = b1;
    c = c1;
    }
    public void main (int x, int y , int z)
    {
        cons c1 = new cons();
        cons c2 = new cons(1,2,3);
        cons c3 = new cons(x,y,z);
        System.out.println(“valfr c1 is “+c1.a+” “+c1.b+””+c1.c);
        System.out.println(“valfr c1 is “+c2.a+” “+c2.b+””+c2.c);
        System.out.println(“valfr c1 is “+c3.a+” “+c3.b+””+c3.c);
    }
}

Comment bellow for your query and feedback… 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!