Simple interface with Package


|  [ Implements ] [ Extends ]



Use of Interface in java programs

Creating method indexing for easy understanding long programs

Creating final keywords

Multiple inheritance possible in java programs using interfaces


Rules of Interfaces

Interfaces and indexing methods must be public

Indexing methods must be override in implemented class


Interfaces inter1 in InterPack1 package

package InterPack1;

public interface Inter1   // Interfaces


public int x = 10;                // it’s final variable

public void method1();  // Indexing | Only Dec


Class A in classStore package

package classStore;

import InterPack1.*;

public class A implements Inter1


public void method1()   // override interfaces method


//x++;   // Can’t increment | dec final interfaces variable

System.out.println(“Welcome in Interface1”);


public void setA()             // own method


System.out.println(“This is Class Method”);



Class Example1 in mainPackage

package mainPackage;

import classStore.*;

import InterPack1.*;

public class Example1


public static void main(String args[])


// How to create interfaces.


//Inter1 ref = new Inter1();         // Error

Inter1 ref = new A();      // Assign object of A class to Inter1 ref…

ref.method1(); // We just call override interface1 method

//ref.setA();                       // Can’t call this method

A a1 = new A();







Welcome in Interface1

This is Class Method


Video available on YouTube.


If you have any query on blog example, you can directly comment us or subscribe our website

Earn Money Online

1432total visits,3visits today


Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.