Why does this compile? (tried under both Oracle java 5 & java 6 (yes, I know, I’m slow to adapt)
public abstract class BaseClass
{
public abstract void methodA(String abc);
public abstract String methodB(String abc);
}
public final class ConcreteClass
extends BaseClass
{
}
Just pop those two classes into separate files, call the javac on them and poof, they compile. Since abstract methods are intended to be implemented by implementors, this doesn’t make sense. Playing with this a bit further, I only receive a compile error when a chunk of code attempts to call the unimplemented method.
So again, my question here is, does anyone know WHY the compiler allows this (or why we would want it to do this)?
Additional comment:
- When I did initial testing, I originally didn’t have the ConcreteClass marked as final, and it occurred to me that another class could extend the class and thus, the complier might not complain and assume that you would have some other class later on down the road take care of it, but marking the class as final should make it pretty clear that this is not the case.
As @Jigar has mentioned in the comment, you must be importing wrong version of
BaseClass. When Itried to compile your code, I get following error: