Day 14 - 04 Oct - Interface
Interface
public interface MyInterface {
// Declare abstract methods method signatures) here void method1();
int method2(String str);
}Interface Examples
Example #01 - Multiple Inheritance Using Basic Interface
interface FirstInterface {
public void myMethod(); // interface method
}
interface SecondInterface {
public void myOtherMethod(); // interface method
}
class DemoClass implements FirstInterface, SecondInterface {
public void myMethod() {
System.out.println("Some text..");
}
public void myOtherMethod() {
System.out.println("Some other text...");
}
}
// Main Class
public class BasicInterfaceExample {
public static void main(String[] args) {
DemoClass myObj = new DemoClass();
myObj.myMethod();
myObj.myOtherMethod();
}
}Example #02 - Area/Perimeter Calculation of Circle and Rectangle Using Shape Interface
Last updated