My question is below the code.
// -- Bird.java
package abcde;
public class Bird {
protected static int referenceCount = 0;
public Bird(){ referenceCount++; }
protected void fly() { /* Flap wings, etc */ }
static int getRefCount() { return referenceCount; }
}
// -- Nightingale.java
package singers;
class Nightingale extends abcde.Bird
{
Nightingale() { referenceCount++; }
public static void main(
String args[])
{
System.out.println("Before: " + referenceCount);
Nightingale florence = new Nightingale();
System.out.println(" After: " + referenceCount);
florence.fly();
}
}
I'm studying the certification book "Java 2 Certification" 2nd edition and I am aware
of all the typos in the book. I looked on the errata page and it didn't mention
anything about the question i'm about to ask. On page 101 it asks which statement
is true about the code that I provided above. The answer is:
The program will compile and the output will beL Before: 0 After: 2
My questions are:
Is the statement "package singers" a typo?
If its not a typo, how can the referenceCount variable be accessed by main without
having the same package name "abcde"?