-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMyClass.java
More file actions
37 lines (28 loc) · 872 Bytes
/
MyClass.java
File metadata and controls
37 lines (28 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
interface MyInterface {
void method();
// Default method
default void defaultMethod() {
System.out.println("Default method implementation");
}
// Static method
static void staticMethod() {
System.out.println("Static method implementation");
}
}
class MyClass implements MyInterface {
// No need to override defaultMethod() as it has a default implementation
@Override
public void defaultMethod() {
System.out.println("custom implementation");
}
public static void main(String[] args) {
MyClass obj = new MyClass();
// Calling default method
obj.defaultMethod(); // Output: Default method implementation
// Calling static method
MyInterface.staticMethod(); // Output: Static method implementation
}
@Override
public void method() {
}
}