Can an abstract class be final?
Answers were Sorted based on User's Feedback
Answer / ranganathkini
No a class cannot be marked "abstract" as well as "final".
Marking a class "abstract" means it contains partial
implementation of methods and hence depends on its
subclasses to provide concrete implementation.
Marking the class "final" means that no other class can
extend it and hence abstract classes cannot be marked final.
Is This Answer Correct ? | 173 Yes | 15 No |
Answer / sekhar
No We can't do that.Because abstract means We compulsory
subclass it.Once we declare a final we can't sub class
that so that we can't do that.
Is This Answer Correct ? | 64 Yes | 12 No |
Answer / ravikiran(aptech mumbai)
no because the purpose of using both are opposite to each
other,An abtract class must have to get instantiated to
become concrete,where as final class should nn't get subclassed
Is This Answer Correct ? | 31 Yes | 6 No |
Answer / raghav
An abstract class is of no use if it cannot be sub classed
because instances of an abstract class cannot be created.
Moreover a class declaration with abstract and final will
not compile at all and when ever a class is marked final,the
properties cannot be extended
Is This Answer Correct ? | 21 Yes | 5 No |
Answer / sudhakar goud
we can't write why because abstract class says it should be
overridden in subclass but where as final class says it
can't be overridden
Is This Answer Correct ? | 13 Yes | 2 No |
Answer / huang
http://java.sun.com/javase/6/docs/jre/api/javaws/jnlp/index.html
The documentation says that
"This class is abstract and final and cannot be instantiated."
for ServiceManager class.
Anyways, the class is not marked as abstract.
Is This Answer Correct ? | 15 Yes | 6 No |
Answer / sudhakar goud
Ans: we can't write both final and abstract
because the abstract say's taht it has to be overridden
where as final say's that it can't be overridden.
That is the reason we can't write both final and abstract
Is This Answer Correct ? | 12 Yes | 4 No |
Answer / yuvaraj
No.Because abstract means We compulsory
subclass it.Once we declare a final we can't sub class
that so that we can't do that.
Is This Answer Correct ? | 7 Yes | 5 No |
Answer / artavazd amirkhanyan
It's good question because of most of people can't explain why we can't have abstract final classes in Java. Most of them says "An abstract class is of no use if it cannot be extended or instantiated". Imagine class where we have 10 static methods and we want them to be final to never be overridden. Now, because of class have only static methods,we can make it abstract and because of restriction on overriding, we can make it final. So abstract final classes can be very useful in aforementioned cases. But we can't have abstract final classes in Java just stupidly because of Java do not let us. And this is one of many silly restrictions of Java.
Is This Answer Correct ? | 3 Yes | 2 No |
What are void methods?
What are the object and class classes used for?
what is polymorhism what is inheritance? what is Abstract n Interface? what if two interfaces have same method and a concrete class is implementing both the interfaces. Will there be a compilation error? What are mutable and immutable classes? How can u make a class mutable? when will u use dem ...explain with example? what is overriding and overloading? what is garbage collection? what is Thread? how do dey communicate? what are the different ways of implementing ? have u used any messaging technologies? what is synchronization? what are some additions in java 1.5? what are generics? whst is advanced for loop? what is finally block? can u have a try in finally? yes!! can u have a finally in finally? how do you write junits? when is a object eligible for garbage collection?explain? a = null and b has ref to a will b be eligible to be garbage collected? sql questions like diff joins? how do dey work? exception handling? what is marker interface? what is the need??
How can final class be used?
what is Vector class?
How to stop a thread in java? Explain about sleep () method in a thread?
How can we use primitive data types as objects?
What will be the output of the program? public class Test { public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("2"); list.add("3"); list.add("4"); list.add("5"); System.out.println("size :"+list.size()); for(int i=0;i<list.size();i++) { list.remove(i); } System.out.println("size after:"+list.size()); } }
What is the purpose of using break in each case of switch statement?
How to sort numbers in java without array?
which pattern is default in scanner package?
To what value is a variable of the Boolean type automatically initialized?