0% found this document useful (0 votes)
40 views

Implementing Interface Ex

The document defines an interface called MyInterface with two public void methods called method1 and method2. A class called Demo implements this interface and provides implementations for both abstract methods to satisfy the interface requirements. When an object of type MyInterface is created using the Demo class, calling method1 on the object prints "implementation of method1" as expected.

Uploaded by

RASHMI DABRE
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Implementing Interface Ex

The document defines an interface called MyInterface with two public void methods called method1 and method2. A class called Demo implements this interface and provides implementations for both abstract methods to satisfy the interface requirements. When an object of type MyInterface is created using the Demo class, calling method1 on the object prints "implementation of method1" as expected.

Uploaded by

RASHMI DABRE
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

interface MyInterface

{
/* compiler will treat them as:
* public abstract void method1();
* public abstract void method2();
*/
public void method1();
public void method2();
}
class Demo implements MyInterface
{
/* This class must have to implement both the abstract methods
* else you will get compilation error
*/
public void method1()
{
System.out.println("implementation of method1");
}
public void method2()
{
System.out.println("implementation of method2");
}
public static void main(String arg[])
{
MyInterface obj = new Demo();
obj.method1();
}
}
Output:

implementation of method1

You might also like