You are here: Home / Topics / Use fields in interface example in Java

Use fields in interface example in Java

Filed under: Java on 2023-09-17 13:15:33

//  Program to use field in interface.

interface AInterface
{
int  SIZE = 100;
void  showA();
}

class Test  implements  AInterface
{
public void showA()
{
 System.out.println("showA() of A interface.");
 System.out.println("SIZE = " + SIZE);
}
}

class  InterfaceTest2
{
public static void main( String args[ ] )
{
 AInterface  a1 = new Test();
 a1.showA();
}
}


Output:

showA() of A interface.
SIZE = 100

About Author:
M
Mr. Dubey     View Profile
Founder and CEO of MCQ Buddy. I just like to help others.