Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>abstract</code> class is not real implementation class. It may contain <code>abstract</code> methods and doesnot need to <code>implement</code> the methods from the <code>interface</code>. It is concern of the REAL implementing class to define the abstract/interface methods.</p> <p>See this difference between abstract class and interface</p> <pre><code>Interface: public interface InterfaceClass { void interfaceMethod(); //no method definition } //Abstract Class implementing InterfaceClass abstract class AbsClass implements InterfaceClass{ abstract void abstractMethod(); public void doSomethingCommon() { System.out.println("Abstract class may contain method definition"); } //no need to implement methods of InterfaceClass because AbsClass is abstract } </code></pre> <p>And here is real class that extends <code>AbsClass</code>: <strong>Its duty of RealClass to define all abstract methods and interface methods.</strong> Additionally, it may <code>override</code> the defined methods in <code>abstract</code> class as well.</p> <pre><code>public class RealClass extends AbsClass{ @Override public void interfaceMethod() { //implement interface method here } @Override void abstractMethod() { } // you may override the doSomethingCommon() of AbsClass too @Override public void doSomethingCommon() { // TODO Auto-generated method stub super.doSomethingCommon(); } } </code></pre> <p>Why there is no compile time error on <code>AbsClass</code>: We cannot create instances of abstract class. That's why there is no meaning of displaying error at compile time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload