Interface:-Interface
is a blue print just like a class. Interface is mainly used for achieving
abstraction. Interface contains public static and final variables and public
abstract methods. An interface can inherit by another interface. An interface
can inherit more than one interface but a class cannot inherit interface, class
can implements one or more than one interfaces. Instantiation of interface is
not possible, we can create object of implemented class so interface reference
can hold object of all implemented classes. All the variables of interface are by
default public static and final, all the methods of interface are automatically
public and abstract.
Interface may be empty, called marker interface.
interface
A
{
}
Interface can contains only variables.
interface
A
{
int a=100;
int b=200;
}
Interface can contains only abstract methods.
interface
A
{
void disp();
void sum();
}
Interface can contain variables and abstract
methods.
interface
A
{
int a=100;
int b=200;
void disp();
void sum();
}
In other words interface is a set of rules and that
all rules must be followed by the implemented classes. If any class not follow
all the rules (not override all methods) than that class must be declared as
abstract class.
Comments
Post a Comment