Interfaces in Java
Interfaces in Java
{
//members
}
Rule-2 : The members which are declared within the interface are automatically 'public'
Note:
The members which are declared within the class without any access modifier
are automatically 'default'.
Rule-3 : The interfaces can be declared with both Primitive Data-Type variables and Non-
Primitive Data-Type Variables.
Rule-4 : The variables declared in interfaces are automatically static and final variables
Note:
static variables in interfaces will get the memory within the interface while
interface loading and can be accessed with Interface-name.
final variables must be initialized with values and once initialized cannot be
modified.(final variables are secured variables)
Rule-5 : The methods which are declared within the interface are automatically Non-Static
abstract methods.
Note:
There is no concept of static abstract methods in interfaces.
Rule-6 : we cannot instantiate interfaces, because the interfaces are abstract components in
Java.(abstract components means physical existence not available)
Rule-7 : These interfaces are implemented to classes through 'implements' keyword and the
classes are known as implementation classes.
Rule-8 : These implementation classes must construct the body for abstract methods of
Interfaces
Rule-9 : The interface can be declared with any number of abstract methods.
Rule-10 : The implementation class must construct body for all abstract methods of Interface.
Rule-11 : Implementation class can be declared with methods other than implemented
methods.
Rule-14 : Interface can extract the features from another interface using 'extends' keyword