Language/Java

default 와 static 예제

원2 2021. 3. 26. 16:04
728x90
반응형

public class Ex7_11 {

	public static void main(String[] args) {
		Child3 c = new Child3();
		c.method1();
		c.method2();
		MyInterface.staticMethod();
		MyInterface2.staticMethod();
		
	}
}

class Child3 extends Parnet3 implements MyInterface, MyInterface2 {
	public void method1 () {
		System.out.println("method1() in Child3");
	}
}
class Parnet3 {
	public void method1 () {
		System.out.println("method1() in Parnet3");
	}
}
interface MyInterface {
	default void method1 () {
		System.out.println("method1() in MyInterface");
	}
	default void method2 () {
		System.out.println("method2() in MyInterface");
	}
	static void staticMethod () {
		System.out.println("staticMethod() in MyInterface");
	}
}
interface MyInterface2 {
	default void method1 () {
		System.out.println("method1() in MyInterface2");
	}
	static void staticMethod () {
		System.out.println("staticMethod() in MyInterface2");
	}
}
728x90
반응형