If a class contains two constructors that take in different types of arguments as shown here:
public class Planet {
public double xxPos; //its current x position
public double yyPos; //its current y position
public double xxVel; //its current veolicity in the x direction
public double yyVel; //its current veolicity in the y direction
public double mass; //its mass
public String imgFileName; //The name of an image in the images directory that depicts the planet
// constructor is like __init__ from python, this sets up the object when called like: Planet(arguments)
public Planet(double xP, double yP, double xV, double yV, double m, String img) {
xxPos = xP;
yyPos = yP;
xxVel = xV;
yyVel = yV;
mass = m;
imgFileName = img;
}
// second constructor
// how come testplanetconstructor knows to use this second one?
// does it know based on the argument type its being passed?
public Planet(Planet p) {
xxPos = p.xxPos;
yyPos = p.yyPos;
xxVel = p.xxVel;
yyVel = p.yyVel;
mass = p.mass;
imgFileName = p.imgFileName;
}
}
My primary question is: 1) How does another class with a main that calls this class determine which constructor to use?
If that is the case, what would happen if you have two constructors with: 2) the same type and number of arguments? 3) the same type but different number of arguments?
I realize that follow up questions are something that you should probably never do (aka something messy). I am just curious.