Monday, 11 May 2015

Interface Example

Exported from Notepad++
import java.util.Scanner; //any java class can implements any number of interfaces but can inherit only one class interface number1{ public void num1(); } interface number2{ public void num2(); } //interface is similar to abstract class. class multi implements number1,number2{ Scanner sc= new Scanner(System.in); int n1,n2; public void num2() { System.out.println("ENter number 2 :"); n2=sc.nextInt(); } public void num1() { System.out.println("Enter number 1 : "); n1=sc.nextInt(); } public void display() { System.out.println("The numbers are = "+n1+" , "+n2); n1*=n2; System.out.println("The multiplication of those two is "+n1); } //since they are implemented all methods belong to interface has to be defined in implemented class } public class Imple { public static void main(String[] args) { multi objmul=new multi(); objmul.num1(); objmul.num2(); objmul.display(); } }


No comments:

Post a Comment