參考 page 7-3 程式範例 Book.java
package books; public class Book { public void show() { System.out.println("Book 物件資訊"); } }
參考 page 7-3 程式範例 ComputerBook.java
package books.computer; public class ComputerBook { public void show() { System.out.println("ComputerBook 物件資訊"); } }
package books.execute; import books.Book; import books.computer.ComputerBook; public class EX01_Execute { public static void main(String[] args) { Book book = new Book(); book.show(); ComputerBook cbook = new ComputerBook(); cbook.show(); } }
javac books\execute\EX01_Execute.java
java books.execute.EX01_Execute
javac -d obj books\computer\ComputerBook.java
java -cp e:\tt\src;. books.execute.EX01_Execute
java -cp e:\tt\src\books.jar;. books.execute.EX01_Execute
參考 page 7-8 表 7-1 各個存取修飾詞可使用的對象
public 完全開放給其他類別
相同套件 package 或 子類別
相同套件 package
不開放給其他類別
private, get, set
abstract class Shape abstract public void show();
參考 page 7-16 程式範例 AbstractClass.java
page 7-18 介面重要規則
interface Book{ void show(); } class ComputerBook implements Book
參考 page 7-20 程式範例 Interface.java
interface IA {} interface IB {} interface IC {} class CA {} class CB {} class CC {} // class CX extends CA, CB {} class CB implements IA, IB {}; // class CY extends IA {} interface IX extends IA, IB {} //interface IY extends CA {} // interface IZ implements IA {}
參考 page 7-24 程式範例 Casting.java
參考 page 7-26 程式範例 Instanceof.java
參考 page 7- 程式範例 Polymorphism.java