Hi folks. I wanted to make sure I understood the basics of constructor overloading, how subclasses inherit the constructors of their superclasses, etc. To that end, I created the following three files (note that these aren't for a real program):
(1) An abstract class called AlienHostile that holds one instance variable (int hitpoints). The class contains two constructors, one no argument constructor that sets hitpoints to 10 by default, and an overloadded constructor that sets hitpoints to an int argument that is passed to the constructor.
(2) A subclass of AlienHostile that has only a single instance variable (boolean recon).
(3) A
test class to see how everything worked. The goal was to create a new AlienFighter object and pass it an int argument (in this case, 23) and then see that the overloaded constructor had in fact been called by calling the getHitpoints accessor method on the object and printing its output.
However, once I compile everything and attempt to run the test class, I get the following error:
(If it's not obvious from the code above, the arrow is pointing towards the
word "new")
If I remove the int argument and the no argument constructor is called, everything works properly.
Any insights would be much appreciated. Thanks!