This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Examulator Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Examulator Question" Watch "Examulator Question" New topic

Examulator Question

Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86
Question No=646

Which of the following statements are true?

1 To be overridden a method must have the same name, parameter types and return type
2 It is possible to override methods in a superclass or the same class
3 classes that are marked as final may not be overriden
4 an overriding method cannot have more access (be more public) than the method being overriden
Answer is 1,3,and 4. But I don't agree with number 4. Maybe it should be "an overriding method cannot have less (be more private_ than the method being overriden.
Please advise.

SCJP 1.4
Tom Adams
Ranch Hand

Joined: Feb 07, 2003
Posts: 56
You are right...the override cannot be more restrictive. The restrictive hiearchy least to most is...
1. public
2. protected
3. <default> - no access modifier
4. private

class ParentClass {
public void Foo() { }
private void Bar() { }
class ChildClass extends ParentClass {
private void Foo() { }// error = more restrictive
void Bar() { }// OK = less restrictive
[ February 13, 2003: Message edited by: Tom Adams ]

Mandar Puranik
Ranch Hand

Joined: Jan 08, 2003
Posts: 35
Hi Maria,
You are correct.
I too solved that question yesterday, and stumbled upon it.
4th one is not correct.

To Bug is Human,<br />To Debug Divine... :-))
jQuery in Action, 2nd edition
subject: Examulator Question