Question 1240 – Nielit STA [02-12-2018]
December 10, 2023Question 1246 – Nielit STA [02-12-2018]
December 10, 2023OOPS
|
Question 108
|
Which of the following is FALSE about inheritance in Java?
|
Private methods are final
|
|
|
Protected members are accessible within a package and inherited classes outside the package
|
|
|
Protected methods are final
|
|
|
We cannot override private methods
|
Question 108 Explanation:
→ Methods declared public in a superclass must also be public in all subclasses (this, by the way, is the reason most of the applet methods are public).
→ Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
→ Methods declared private are not inherited and therefore this rule doesn’t apply.
→ Methods declared without protection at all (the implicit package protection) can be declared more private in subclasses.
→ Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
→ Methods declared private are not inherited and therefore this rule doesn’t apply.
→ Methods declared without protection at all (the implicit package protection) can be declared more private in subclasses.
Correct Answer: C
Question 108 Explanation:
→ Methods declared public in a superclass must also be public in all subclasses (this, by the way, is the reason most of the applet methods are public).
→ Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
→ Methods declared private are not inherited and therefore this rule doesn’t apply.
→ Methods declared without protection at all (the implicit package protection) can be declared more private in subclasses.
→ Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
→ Methods declared private are not inherited and therefore this rule doesn’t apply.
→ Methods declared without protection at all (the implicit package protection) can be declared more private in subclasses.
