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.
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
Joined: Feb 16, 2000
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?
Joined: Apr 05, 2000
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...
Hi 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. Michael [ October 24, 2003: Message edited by: Michael Fitzmaurice ]
"One good thing about music - when it hits, you feel no pain" <P>Bob Marley