Interfaces in Java, What are interfaces in java, java interfaces questions, interface in java
- An interface is a group of related methods with empty bodies. eg.
- interface example{
- void A(int a); // method A
- void B(int b);//empty methods
- }
- It introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods.
- A nested interface is any interface whose declaration occurs within the body of another class or interface. A top-level interface is an interface that is not a nested interface.
- A class may be declared to directly implement one or more interfaces, meaning that any instance of the class implements all the abstract methods specified by the interface or interfaces. A class necessarily implements all the interfaces that its direct superclasses and direct superinterfaces do. This (multiple) interface inheritance allows objects to support (multiple) common behaviors without sharing any implementation.
- Interface Modifiers
- Allowed modifiers are
- InterfaceModifier: one of public, protected, private, abstract, static, strictfp
- abstract Interfaces - Every interface is implicitly
abstract. This modifier is obsolete and should not be used in new programs.