Thursday, 4 September 2014

JAVA Use Interface with Abstract Class

package com.mastermoin.ICore;

public interface InterfaceOne {
       void methodFromInterfaceOne();
}

________________________________________________________________________

package com.mastermoin.ICore;

public interface InterfaceTwo {
       void methodFromInterfaceTwo();
}
________________________________________________________________________ 

package com.mastermoin.ICore;

public abstract class AbstractDemo  implements InterfaceOne,InterfaceTwo{

       @Override
       public void methodFromInterfaceOne() {
              System.out.println("From Interface One : implements in Abstract Class ");
       }

}

 __________________________________________________________________________

package com.mastermoin.java;

import com.mastermoin.ICore.AbstractDemo;

public class DemoRun extends AbstractDemo{

       public static void main(String[] args) {
              DemoRun obj = new DemoRun();
              obj.methodFromInterfaceOne();
              obj.methodFromInterfaceTwo();
       }

       @Override
       public void methodFromInterfaceTwo() {
              System.out.println("From Interface Two & Abstract Class : Implements in DemoRun Class");
             
       }

}
  __________________________________________________________________________
Output

From Interface One : implements in Abstract Class
From Interface Two & Abstract Class : Implements in DemoRun Class

No comments:

Post a Comment