The moose likes Beginning Java and the fly likes Method Overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method Overriding" Watch "Method Overriding" New topic

Method Overriding

Betty Reynolds
Ranch Hand

Joined: Feb 16, 2000
Posts: 111
Can methods of the following types be overridden in classes?
- native
- synchronized
- abstract
Also, interfaces are implicitly abstract, yet they use overriding methods. An interface that extends another and has overriding methods for its superclass methods is just overriding the prototype statement, but what is the point? The only thing you could do is perhaps widen the accessibility or narrow the exceptions.
John Wetherbie

Joined: Apr 05, 2000
Posts: 1441
I think the answer is yes to all. Overriding abstract methods is their reason for existence. Overriding a native function in a Java class would seem to be like overriding an abstract method just to change its accessibility since native methods don't have bodies. You can override synchronized methods but I don't think you inherit the synchronization. (Can someone check me on that?)
As far as having interfaces extending other interfaces, that is usually done to build up an "meta" interface (for lack of a better term) that will then be implemented. The great thing about Java vs C++ is that the interface is a construct in the language itself. When you have an object/class/hierarchy that is used by a large part of your system the best approach, in a lot of cases, is to present a single interface that abstracts/shields the system from changes that may occur underneath the interface. The Java interface with its automatically abstract methods (and some constants, if necessary) was designed with this in mind. (OK, I'm off my little OO soapbox...)

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Betty Reynolds
Ranch Hand

Joined: Feb 16, 2000
Posts: 111
Thanks John for putting interfaces in context. It's clearer now. If you don't mind my asking, are you currently doing Java development at work?
John Wetherbie

Joined: Apr 05, 2000
Posts: 1441
The answer is yes and no. I am an architect/developer but lately there hasn't been much development, mostly requirements gathering and analysis. I try to do a little coding each day, just trying new things out. Studying for the SCJP exam provides additional motivation for this. I've been doing Java professionally for 9 months and before that I had been doing OO/C++ for 6 years.
Maybe a short "yes" would have sufficed...
qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
implementing abstract method of abstract class,is it one kind of method overriding?

Thanks...qingwu<br />When I open my eyes,I see your pretty face.
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Yes, that is indeed one type of method overriding. Just reading the original post - I think its worth stressing that methods in an interface are implicity public and abstract. Hence, you cannot change the access by extending one interface into another - all methods in an interface can only be public.
[ October 24, 2003: Message edited by: Michael Fitzmaurice ]

"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
I agree. Here's the link: http://aspose.com/file-tools
subject: Method Overriding
Similar Threads
Abstract class HttpServlet question
OOPS concepts implementation in Java
Interface question