Interface in Java

Interface in Java:

We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it.

In Java, the interface is an abstract type. It is used to specify an interface that classes must implement. Interfaces are declared using the “interface” keyword. It may contain method signature and constant declarations. It never contains methods definitions. Interfaces are implemented, rather than instantiated.

Interface usage in Java:

  • In Java, class never supports multiple inheritance whereas interface supports multiple inheritance.
  • When the programmer develops a project then it is advisable that the programmer should declare an interface. When the programmer declares an interface then it becomes easier to modify and add new features in the projects as nothing is defined in an interface.
java interface example
interface In 
{
	void show();
	void display();
}

public class Interface {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		In in = new In()
		 {
			public void show() 
			{
				
				System.out.println("Hello Gk Scientist");
			}
			
			public void display() 
			{
				
				System.out.println("Today we learn about Interface in Java");
			}
			
		};
		
		in.show();
		in.display();
	}

}

Tutorial Python
Tutorial MySQL
Email (Electronic Mail)
Operating System (OS)
Computer Network
Database Models or Data Models
Java (programming language)– Wikipedia

Comments (No)

Leave a Reply