Interface with extends

Interface class
===========
an interface class extends with another interface class and implements with a class. example code shown below.
import java.io.*;
interface interone
{
    public void addition() throws IOException;
}
interface intertwo
{
    public void subtraction() throws IOException;
}
interface interthree extends intertwo            // An interface class can be extended to another interface class
{
      public void multiplication() throws IOException;
}

class exampleclass1 implements interone,interthree   
{
  DataInputStream ds=new DataInputStream(System.in);
    int a,b,c;
    public void addition() throws IOException
    {
            System.out.println("Enter two values for Addition");
            a=Integer.parseInt(ds.readLine());
            b=Integer.parseInt(ds.readLine());
            c=a+b;
            System.out.println("Addition values: "+c)    ;
    }
    public void subtraction() throws IOException
    {
      
            System.out.println("Enter two values for Subtraction");
            a=Integer.parseInt(ds.readLine());
            b=Integer.parseInt(ds.readLine());
            c=a-b;
            System.out.println("Subtraction values: "+c)    ;  
    }

    public void multiplication() throws IOException
    {
        
            System.out.println("Enter two values for Multiplication");
            a=Integer.parseInt(ds.readLine());
            b=Integer.parseInt(ds.readLine());
            c=a+b;
            System.out.println("Multiplication values: "+c)    ;
   }
}
class ExampleClass1  extends exampleclass1// Inhereit base class and define interface methods 
{
     public void division() throws IOException
    {
        
            System.out.println("Enter two values for Multiplication");
            a=Integer.parseInt(ds.readLine());
            b=Integer.parseInt(ds.readLine());
            c=a/b;
            System.out.println("Division values: "+c)    ;
   }

}
class MainClass1
{
    public static void main(String args[]) throws IOException
    {
        ExampleClass1 ec=new ExampleClass1();
        ec.addition();
        ec.subtraction();
        ec.multiplication();
        ec.division();
    }
}

Comments

Popular posts from this blog

Amount in to text conversion program in C

Abstract and Final Class sample