• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Examulator Question

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maria,
You are correct.
I too solved that question yesterday, and stumbled upon it.
4th one is not correct.
Thanks
Mandar
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic