❮ Previous Next ❯

Constructor Overloading in java

It is possible to define more than one constructor in a program, which is known as Constructor Overloading or multiple constructor.


Example

class Example
{
int x,y;
Example()
{
x = 0;
y = 0;
}
Example(int z)
{
x = y = z;
}
Example(int p, int q)
{
x = p;
y = q;
}
void show()
{
System.out.println(x+" "+y);
}
}
class TestExample
{
public static void main(String[] args)
{
Example obj1 = new Example();
Example obj2 = new Example(5);
Example obj3 = new Example(2,3);
obj1.show();
obj2.show();
obj3.show();
}
}
Output

0 0
5 5
2 3


❮ Previous Next ❯


  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved