• Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding  RSS feed

 
sri jaisi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While overriding wat are the rules for access specifiers-watz more restricitve and less restrictive

can a static variable and instance variable be in same name
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public, protected, default, private

less restrictive.....more restrictive

:-)

for the second question...you don't have compiler?
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Exceptions should not be more super type but may be sub type of overriding method.
Access specifiers may be less restrictive.
 
Anil Pattnaik
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiiiii,

Coming to overridding concept.....When we override any parent class method inside child class,the child class cannot restrict the access specifier of parent class inside child class.

suppose parent class method have a "public" method,when child class method overrides that method it cannot make that method as private/default/protected.

Similarly if parent class method has "protected" method,then child class cannot make its method as a private/default.

When it comes to Exception handling....
(1)the child class method can throw the same Exception or subclass of that Exception which the perent class method is throwing.....only if the parent class method is throwing "compile time/Checked Exception."

(2)The child class method can throw Exception other than what the parent class method is throwing only if the parent class method is throwing RunTimeExceptions........Read alll these point carefully.i hope everybody can understand,bye.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way of looking at the rules about new Exceptions or access modifiers; no method of a subclass may make any more demands on its clients than its superclass counterpart.
You can't insist the client handle any more exceptions and can't insist on any more restrictive access. Otherwise you couldn't use polymorphism.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!