interface IntExample{
//Syntax-<modifier> <return-type>
methodName(<optional-parameters>);
// Methods declared in the interface are implicitly
public and abstract.
public void sayHello();
}
}
/*
Classes are extended while interfaces are implemented.
To implement an interface use implements keyword.
IMPORTANT : A class can extend only one other class, while it
can implement n number of interfaces.
*/
public class JavaInterfaceExample implements IntExample{
public void sayHello(){
System.out.println("Hello Visitor !");
}
public static void main(String args[]){
//create object of the class
JavaInterfaceExample javaInterfaceExample = new
JavaInterfaceExample();
//invoke sayHello(), declared in IntExample interface.
javaInterfaceExample.sayHello();
}
}
OUTPUT
Hello Visitor !
No comments:
Post a Comment