Create a class called Planet. A planet's state is it's name and a list (array) of moons that it has. You can assume there is a Moon class that a single constructor that takes it's name as input (a String). Add three constructors to your Planet class: Planet(String planetName) (planet has no moons) Planet(String planetName, String moonName) (planet has one moon) Planet(String planetName, Moon[] moons) (planet has arbitrary number of moons). Be sure to use constructor chaining. Question: When creating a planet object, what is the minimum number of constructors that are called (in total, either explicitly by you or by the JVM)? What is the maximum number of constructors that might be called (in total, either explicitly by you or by the JVM)? Give an example for each
Create a class called Planet. A planet's state is it's name and a list (array) of moons that it has. You can assume there is a Moon class that a single constructor that takes it's name as input (a String). Add three constructors to your Planet class:
Planet(String planetName) (planet has no moons)
Planet(String planetName, String moonName) (planet has one moon)
Planet(String planetName, Moon[] moons) (planet has arbitrary number of moons).
Be sure to use constructor chaining.
Question: When creating a planet object, what is the minimum number of constructors that are called (in total, either explicitly by you or by the JVM)? What is the maximum number of constructors that might be called (in total, either explicitly by you or by the JVM)? Give an example for each.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images