How can we prevent a Interface for being extended by a other interface? Surely final will not work,is there any way of doing so?
First of all, interfaces are made accessible from any class hierarchy, no bondage in general. But
Yeah you can do that, place the interface inside a class and make it private so that outside the class nobody could extend it! It would be for personal use in the class (by the innerclasses and so) to implement it or extended by another interface in the same class but looks little clumsy.
Interfaces are created to to be implemented by classes, whereas class can be made final to be not extended.
I only meant, the purpose of having an interface is availed when a class implements it and avails the benefit of polymorphism too. The question was "How can be prohibit an interface to be extended by another interface". To extend an interface means to give more burden to the concrete (implementing)class. Sometimes we may want to not allow other interface to extend it, we can make it private but inside a class. We call it nested interface.
But what we generally see, standard interfaces are made public to be implemented by any classes to avail their benefits.
Well what I was thinking that you were saying was that interfaces are visible by all classes (except when nested like you said), but you can obviously give an interface default access, in which case only classes inside that package can implement it, or even see it. That's useful for developing low level components in a de-coupled fashion.
That might achieve what Sanjeev was really tring to do (not quite the same), though one of the main purposes of interfaces is not to restrict implementation to a single class - I think that's worth understanding!
In anycase, this is not really anything to do with SCJP...
This looks like a job for .... legal tender! It says so right in this tiny ad: