Can an interface contain static methods in Java?
- No
- Only if it doesn't have any abstract methods.
- Only if it doesn't have any default methods.
- Yes
Yes, Java allows interfaces to contain static methods, introduced in Java 8. Static methods in interfaces can be called without creating an instance of the interface and are often used for utility functions or factory methods.
Loading...
Related Quiz
- Which keyword is used in Java to test a condition?
- In Java, if a class implements an interface and does not provide implementations for all its methods, it must be declared as ________.
- Which class allows you to read lines of text from a file?
- Imagine a situation where you need to insert a large dataset (for example, 10,000 rows) into a database using JDBC. How would you optimize this process to ensure that it is done efficiently and does not consume excessive resources?
- When would you prefer byte streams over character streams while performing I/O operations in Java?