1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
/* Java Interface example. This Java Interface example describes how interface is defined and being used in Java language. Syntax of defining java interface is, <modifier> interface <interface-name>{ //members and methods() } */ //declare an interface interface IntExample{ /* Syntax to declare method in java interface is, <modifier> <return-type> methodName(<optional-parameters>); IMPORTANT : 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{ /* We have to define the method declared in implemented interface, or else we have to declare the implementing class as abstract class. */ 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 of the above given Java Interface example would be : Hello Visitor ! */ |
Explaining with example is better to understand
please teach mo how t use it ^_^
wat d ……….
It says that inorder to avoid complexity in java,pointer concept is not using.Then how can we implement the concept of linked list in java?
line 23 brace is not needed
it looks like there may be an extra closing bracket under public void sayHello();
I made new project named IntExample and pasted code into but NetBeans says:”error:class JavaInterfaceExample is public, should be declared in a file named JavaInterfaceExample.java”.Any help?
According to my knowledge you are trying to make two public methods in same program (Which is not possible).Try to make another package and import your interface in that new package.
dear you will try using different class name and diff object then I would be give you correct
answer
keep the file name as JavaInterfaceExample.java and class name as JavaInterfaceExample in the project source file code.
ie. IntExample>Source(package)>JavaInterFaceExample(class name), right click and Refactor.