困惑記錄 接口的繼承

 


public class ByteStudy {

	public static void main(String[] args) {
		MyClass ob = new MyClass();
		ob.meth1();
		ob.meth2();
		ob.meth3();

	}

	// One interface can extend another.
	interface A {
		void meth1();

		void meth2();
	}

	// B now includes meth1() and meth2() -- it adds meth3().
	interface B extends A {

		void meth3();
	}

	// This class must implement all of A and B
	static class MyClass implements B {

		public void meth1() {
			System.out.println("Implement meth1().");
		}

		public void meth2() {
			System.out.println("Implement meth2().");
		}

		public void meth3() {
			System.out.println("Implement meth3().");
		}
	}

}

理論上根據課本代碼應該報錯,然鵝並沒有,代碼可以正常輸出。課本想表達的意思應該是接口B中應該實現void math1()和void math2(),不知道這樣理解對不對,記錄一下

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章