Complete the code to declare a static method in an interface.
public interface Calculator {
static int [1](int a, int b) {
return a + b;
}
}The method name add is used as the static method name in the interface.
Complete the code to call the static method from the interface.
int result = Calculator.[1](5, 3);
The static method add is called using the interface name.
Fix the error in the static method declaration inside the interface.
public interface Printer {
[1] void print(String message) {
System.out.println(message);
}
}The method must be declared static to be a static method in an interface.
Fill both blanks to define and call a static method in an interface.
public interface Utils {
static String [1](String s) {
return s.toUpperCase();
}
}
String result = Utils.[2]("hello");The static method name toUpperCase is used both in declaration and call.
Fill all three blanks to create a static method in an interface that returns the square of a number and call it.
public interface MathOps {
static int [1](int n) {
return n [2] n;
}
}
int squared = MathOps.[3](4);The method square multiplies the input by n using the '*' operator and is called as MathOps.square(4).
