I didn’t find any reason of adding abstract keyword with class name when we have already added abstract keyword with the corresponding method. But there could be a reason of less code implementation and less execution of code. Let me explain you :
Suppose i have 2 classes namely A and B. In A i have 1 abstract method getData() and in B i don’t have any abstract method. In this case i am taking example of class which doesn’t have abstract keyword with class name. Now whenever we extend class A in our main class then at the compiler have to check all methods to check if there is any abstract method or not. Suppose this takes 3 milliseconds to check. When we are extending class A, it takes 3 milliseconds to check if class A has any abstract method or not. This seems to be OK. But in case of B when we don’t have any abstract, it wastes 3 milliseconds by checking for abstract methods. This could be much more.
So maybe compiler first check for abstract keyword with class name. If it tells that yes this class is a abstract class then only it check for all abstract methods. And if it says that the class doesn’t have any abstract method, it skips the checking logic for abstract method.
*This may not be the right answer. This is what i think maybe the answer.
Leave a Reply