A
AIK
I have the following two classes:
package birdpack;
public class Bird {
Bird() {}
protected int nFeathers;
}
in bird.java
and
package duckpack;
import birdpack.Bird;
public class Duck3 extends Bird {
Duck3() {}
void foo() {
Bird b = new Bird();
int temp;
temp = b.nFeathers;
}
}
in Duck3.java
When I compile Duck3 I get this error: nFeathers has protected access in
birdpack.Bird. Why is this? I thought the point of a protected modifier is
to allow children of a class to access parent's protected feature even if
the child class is in a different package?
package birdpack;
public class Bird {
Bird() {}
protected int nFeathers;
}
in bird.java
and
package duckpack;
import birdpack.Bird;
public class Duck3 extends Bird {
Duck3() {}
void foo() {
Bird b = new Bird();
int temp;
temp = b.nFeathers;
}
}
in Duck3.java
When I compile Duck3 I get this error: nFeathers has protected access in
birdpack.Bird. Why is this? I thought the point of a protected modifier is
to allow children of a class to access parent's protected feature even if
the child class is in a different package?