aspose file tools*
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
Author

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 ]

Tom
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.
Thanks
Mandar


To Bug is Human,<br />To Debug Divine... :-))
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Examulator Question