How to Implement a Static Member Interface in Java


In this example we will show how tocreate the static member Operation interface in MemberInterfaceClass and implement the interface in TestClass, as shown below.

Source Code

1 MemberInterfaceClass)

package com.beginner.examples;

public class MemberInterfaceClass {

	public static interface Operation{
		
		void sum(int a,int b);
		
		void sub(int a,int b);
	}
	
}

2 TestClass)

package com.beginner.examples;

public class TestClass implements MemberInterfaceClass.Operation {

	@Override
	public void sum(int a, int b) {

		System.out.println(a + " + " + b + " = " + (a + b));

	}

	@Override
	public void sub(int a, int b) {

		System.out.println(a + " - " + b + " = " + (a - b));
	}

	public static void main(String[] args) {

		TestClass t = new TestClass();

		t.sum(20, 21);
		t.sub(22, 20);
		

	}

}

Output:

20 + 21 = 41
22 - 20 = 2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments