I have this two classes, Dog
and Beagle
that extends Dog
.
class Dog {
protected String bark() {return "woof "; }
}
class Beagle extends Dog {
private String bark() { return "arf "; }
}
class Test {
public static void main(String args[]) {
Dog[] dogs = {new Dog(), new Beagle()};
for(Dog d : dogs)
System.out.print(d.bark());
}
}
When I'm using any other editor rather than Eclipse, the above code it does not even compile. I'm getting this error:
Attempting to assign weaker access privileges to bark() method in Beagle class.
You can also see this behavior here.
If I use Eclipse Indigo (Version: 3.7.2), this code compiles fine and the output is: woof woof
.
Please make me understand which one is correct and why?
Thanks in advance!
Cannot reduce the visibility of the inherited method from Dog
. Clean your Project and rebuild it. I guess than the Problem is not longer reprduceable – Jens Jun 21 '17 at 12:35Version: 3.7.2
. Is this version so old? – Joan P. Jun 21 '17 at 12:36