I have seen this question and it is one of the many sample question to prepare you for SUN Certication. You can find the question in this doc: Sun Certification.
There are some sites that have this question, however they are missing components or is written incorrectly which will not compile, however the answer is still 420;
I will assume the the OP copy and pasted the code from one of those sites.
The proper code should be two separate class written as:
class ClassA {
public int numberOfInstances;
protected ClassA(int numberOfInstances) {
this.numberOfInstances = numberOfInstances;
}
}
public class ExtendedA extends ClassA {
private ExtendedA(int numberOfInstances) {
super(numberOfInstances);
}
public static void main(String[] args) {
ExtendedA ext = new ExtendedA(420);
System.out.print(ext.numberOfInstances);
}
}
To answer the question on how this works:
The child class can access its Parent's constructor by calling super(...) and therefore in this case assigning 420 to numberOfInstances. If you are not familiar with inheritance, I recommend you research this on your own, however, to make is short, the child class or subclass inherits all of the public and protected members of its parent.
So when you call ext.numberOfInstances, the output will be 420. The value is assigned by first calling the subclass contructor, then the subclass constructor call the parent constructor using super(420) which then assign the value to numberOfInstances.