Bango Bango - 2 years ago 85
Java Question

how do you know what parameters go inside the parentheses when creating a new object?

I am in the process of learning java programming.
so sometimes i see code that looks like this:

Shape ball= new Shape();.// takes no parameter
Shape ball= new Shape(1,2); //takes parameter

My question is, when an object has multiple constructors that take different paramaters, how do you know which constructor to use?

Answer Source

Look at the documentation for the class. That's the only surefire way to know. The Shape class you provided likely has two constructors:

Shape() //default no-args
    //do something

Shape(int a, int b)
    //do something with a and b
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download