1.What is an Interface?
2.Can we instantiate an interface?
3.Can we create an object for an interface?
4.Do interfaces have member variables?
5.What modifiers are allowed for methods in an Interface?
6.What is a marker interface?
An interface is a description of a set of methods that conforming implementing classes must have.
Note:
Note:
- You can’t mark an interface as final.
- Interface variables must be static.
- An Interface cannot extend anything but another interfaces.
You can’t instantiate an interface directly, but you can instantiate a class that implements an interface.
3.Can we create an object for an interface?
Yes, it is always necessary to create an object implementation for an interface. Interfaces cannot be instantiated in their own right, so you must write a class that implements the interface and fulfill all the methods defined in it.
4.Do interfaces have member variables?
Interfaces may have member variables, but these are implicitly
public, static,
and final
- in other words, interfaces can declare only constants, not instance variables that are available to all implementations and may be used as key references for method arguments for example.5.What modifiers are allowed for methods in an Interface?
Only
public
and abstract
modifiers are allowed for methods in interfaces.6.What is a marker interface?
Marker interfaces are those which do not declare any required methods, but signify their compatibility with certain operations. The
Differences between Interface and Abstract class
java.io.Serializable
interface andCloneable
are typical marker interfaces. These do not contain any methods, but classes must implement this interface in order to be serialized and de-serialized.Differences between Interface and Abstract class
EmoticonEmoticon