This is an excerpt from Oracle's Java tutorial website. It doesn't show the actual .java files, but I'm guessing "Rectangle" is a class. But if you note, the parameters passed down (by value?) for rectOne and rectTwo are different. (one has the origin variable while two does not)
If the object has certain number of parameters, can the actual number of passed down values be less than that? I'm assuming it can't be more by default.
Also, I searched for answers but cannot find.
// Declare and create a point object and two rectangle objects.
Point originOne = new Point(23, 94);
Rectangle rectOne = new Rectangle(originOne, 100, 200);
Rectangle rectTwo = new Rectangle(50, 100);
An object doesn't have parameters - a method or a constructor does. In this case, basically there are two overloaded constructors. For example:
public Rectangle(Point origin, int width, int height)
{
this.origin = origin;
this.width = width;
this.height = height;
}
public Rectangle(int width, int height)
{
this(Point.ZERO, width, height);
}
The only time in which the number of argument expressions for a single overload can vary is with varargs:
public void foo(String... bar)
{
...
}
foo("x"); // Equivalent to foo(new String[] { "x" })
foo("x", "y"); // Equivalent to foo(new String[] { "x", "y" })
foo("x", "y", "z"); // Equivalent to foo(new String[] { "x", "y", "z" })
See more on this question at Stackoverflow