This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
When I try to call a parent class constructor in a subclass that I defined, it tries to look for a non-arg constructor.
I know that in a constructor, super() is called by default. So in that case, super() of class A i.e Object does have this default constructor, so why is it trying to call B's constructor?
// Error: constructor A in class A cannot be applied to given types;
required: String found: no arguments
reason: actual and formal argument lists differ in length
All constructors result in a call to a superclass constructor at some point. If you don't make an explicit call yourself, the compiler inserts one for you. But it will always insert a call to a no-arg constructor (if it used arguments, what would it pass?).
So the compiler is treating your code as if it was:
So it's trying to call the no-arg contructor in A, and that doesn't exist. That's a compiler error. It doesn't matter that your main method never tries to create a B - the compiler won't let you refer to constructors, methods or variables that don't exist.