class Office Employee extends Employee double weight double

  • Slides: 9
Download presentation

繼承範例 class Office. Employee extends Employee { double weight; double height; Office. Employee (String

繼承範例 class Office. Employee extends Employee { double weight; double height; Office. Employee (String s, int i) { super(s, i); } // Constructor 繼承自class Employee, 使用關鍵字 extends super代表被繼 承的物件,也 就是Employee

範例 abstract class Student{ String name; String ID; int grade; public Student() { }

範例 abstract class Student{ String name; String ID; int grade; public Student() { } // Constructor � � � abstract public void compute. Grade(int extra); public String get. ID() { return ID; }//get. ID() }// Student Abstract修飾的 方法,在繼承 的class中定義 其用法。

Implements public interface Area. Interface{ double area(); // 面積 double circ(); // 週長 }//Area.

Implements public interface Area. Interface{ double area(); // 面積 double circ(); // 週長 }//Area. Interface 此interface中定義兩個 方法,其純粹只是一個 想法。 class Square. Area. Implements implements Area. Interface{ double w, h; Square. Area. Implements (double w, double h) { this. w = w; this. h = h; }//Constructor public double area() {return w*h; } public double circ() {return 2*(w+h); } }// Square. Area. Implements 此class實現 Area. Interface, 必須完成其中所 定義的方法,因 為楮瑥牦慣e中 定義的方法視為 abstract修飾的 方法。

多重繼承 Class A Interface B extends implements Class C extends class. A implements interface.

多重繼承 Class A Interface B extends implements Class C extends class. A implements interface. B