Anything that is defined as abstract cannot be defined as final. Interfaces are always abstract regardless of whether one types the word abstract. for example: when you write public interface A{....} it is actually public abstract interface A{...} // in fact you can type in this syntax too
So Abstract Classes and Interfaces CAN NEVER BE FINAL
A final class cannot be extended. A final method cannot be overridden. A final variable cannot be modified.
If you have a final class then you cannot extend. If you make an abstract class as final then you cannot extend it to provide the missing functionality. Therefor you cannot have an abstract class as final as it goes agains extensibility and basic purpose of having an abstract class!
Thanks! Rohit Nath
Ernest Friedman-Hill
,
author and iconoclast
staff
Sometimes you'll want to create a class that can neither be extended nor instantiated. java.lang.Math, java.lang.System, and java.lang.Collections are all like this. If you could define the class as "abstract final", that would do the trick, so perhaps that's what he's interested in. The right way to do this in Java is just to give the class a single empty constructor, and make it private. If a class's only constructor is private, then it can't be extended (well, except by its own inner classes) nor instantiated (except by code inside its own class body.)