Programmer's Rules


Rules of declaring and implementing interfaces in Java

Job interview question for Java developers

Javajob interviewOCA

1. Before the interface declaration there may be an abstract modifier.

2. Interfaces can be implemented by any class from any inheritance tree.

3. Methods in an interface cannot be final or static and are always public and abstract.

4. Variables in an interface are always public static final so cannot be private or protected.

5. Interface implementation by a class cannot declare a new checked exception for an implementation method.

6. Interface implementation by a class cannot declare a checked exception broader than that in an interface for an implementation method.

7. Interface implementation by a class can declare for an implementation method any runtime exception regardless of the exception declared in the interface method.

8. An overridden method in a class that implements interface must have the same type of return value but doesn't have to implement the exception declared in an interface method.

9. Interfaces can extend one or more other interfaces (e.g interface A extends B, C, D).

10. Interfaces cannot extend a class, or implement a class or interface.
Tutorial statistics