fork download
  1. class Dog {
  2. protected String bark() {return "woof "; }
  3. }
  4. class Beagle extends Dog {
  5. private String bark() { return "arf "; }
  6. }
  7.  
  8.  
  9. class Test {
  10. public static void main(String args[]) {
  11. Dog[] dogs = {new Dog(), new Beagle()};
  12. for(Dog d : dogs)
  13. System.out.print(d.bark());
  14. }
  15. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: bark() in Beagle cannot override bark() in Dog
	private String bark() { return "arf "; }
	               ^
  attempting to assign weaker access privileges; was protected
1 error
stdout
Standard output is empty