You have declared your own constructor that takes an int. If you define your own constructor with any signature, java will not create the no-arg version by default.
Then, in your class B, you make a call for the no-arg constructor of a 'B' object. Since a B IS-AN A, you are effectively calling the no-arg constructor for 'A', which doesn't exist. That is what the compiler is telling you.
You can fix this by defining a no-arg constructor for your 'A' class.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
The first line in each constructor is either a call to a super constructor or a call to another constructor of the same class. If this is not written explicitly by the programmer, the compiler implicitly will put a call to "super()". Which what the compiler does to your B() constructor.
However, super() in this case is A(), which does not exist.
So look how you treat the integer in A(int a). What do you do with it? How would you then expect passing different values into that constructor would affect how the application runs?
Originally posted by Oscar E Rodriguez: Thank you, Rob and Campbell, for the feedback.
I understand now the need for a value to be placed in for "X", but does the value I choose to put in there affect how the code executes?
I've tired different values for "X" and executed the main and haven't noticed any diffence in the output.
Joined: Oct 13, 2005
Change to thisThe problem is that you are not using the X argument. The second version should correct your original errors, and uses that argument.
You weren't using the constructor properly; the idea of a constructor is to set the initial values of all the fields. You left "x" alone, so it will default to 0. Don't have a field of the same name in a subclass; that can cause no end of confusion later on.