Which is a valid abstract class?
A.
public abstract class Car {
protected void accelerate();
}
B.
public interface Car {
protected abstract void accelerate();
}
C.
public abstract class Car {
protected final void accelerate();
}
D.
public abstract class Car {
protected abstract void accelerate();
}
E.
public abstract class Car {
protected abstract void accelerate() {
//more car can do
}}
The only correct class declaration is D.
Why not A: the method in abstract class may miss it’s declaration ONLY if it is marked with the “abstract” modifier
Why not B: we can’t use methods with modifier other then public with interface methods (just to note: the default access mode of interface method is equivalent to the pulic)
Why not C: what is the reason to finalize methods provided for implementstion? 🙂
Why not E: abstract class can not have it’s abstract methods declaration.
A missing abstract or missing body.
B an interface is not an abstract class.
C missing body
E abtstact method cannot have a body.
Yes, The correct answer is D