Interface in Java
Java is the most popular programming language and it is the most secure language, Here we learn about one of the most important features of java, Interface in Java.An interface is a reference type in Java and it is similar to a class, Interface is a collection of abstract methods. The main use of the interface in java is to achieve multiple inheritances in java.
When we need Interface
When you want to give clients the flexibility to provide their own implementation of a method, which could be located across various components, interfaces are the better option.Example of Interface in Java
interface Walking
{
void run();
}
class Man implements Walking
{
public void run()
{
System.out.println("Run Fast");
}
public static void main(String args[])
{
Man obj = new Man();
obj.run();
}
}
Output:
Run Fast
No comments:
Post a Comment