static
keyword.
interface MyInterface
{
// Abstract method (must be implemented by implementing classes)
void m1();
// Static method (can be called using interface name)
static void m2()
{
System.out.println("This is a static method inside an interface.");
}
}
class MyClass implements MyInterface
{
@Override
public void m1()
{
System.out.println("Implementation of abstract method.");
}
}
public class MainApp2
{
public static void main(String[] args)
{
MyClass obj = new MyClass();
obj.m1(); // Calls implemented abstract method
MyInterface.m2(); // Calling static method using interface name
}
}
Implementation of abstract method. This is a static method inside an interface.
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weโre here to make our tutorials better based on your thoughts and suggestions.