Given:
public class Dog {
protected String bark() {return “woof “; }
}
public class Beagle extends Dog {
private String bark() { return “arf “; }
}
public class TestDog {
public static void main(String[] args) {
Dog[] dogs = {new Dog(), new Beagle()};
for(Dog d: dogs)
System.out.print(d.bark());
}
}
What is the result?
A.
woof arf
B.
woof woof
C.
arf arf
D.
A RuntimeException is generated
E.
The code fails to compile
‘protected String bark()’ from Dog and ‘private String bark()’ from Beagle which extends Dog won’t be compiled
Code fails to compile.
“attempting to assign weaker access privileges; was protected”
So correct answer is E
Correct answer is E
Cannot reduce the visibility of the inherited method from Dog
The correct answer is B “woof woof”
private String bark() { return “arf “; } <– because the bark method on beagle is private
You’re wrong !!!
Attempting to assign weaker access privileges (private < protected)
Correct answer is E
Correct answer should be E
Bark() in Beagle cannot override bark() in Dog; attempting to assign wearker access privilege: was proteted.
finally E
E is the correct one
E
E.
e
E
E also all classes are public this is wrong