1. public abstract class Shape{
2. private int x;
3. private int y;
4. public abstract void draw();
5. public void setAnchor(int x, int y){
6. this.x = x;
7. this.y = y;
8. }
9. }
Which two classes use the Shape class correctly? (Choose two.)
A. public class Circle implements Shape{
private in radius; }
B. public abstract class Circle extends Shape{
private in radius; }
C.
public class Circle extends Shape{
private in radius;
public void draw(); }
D.
public abstract class Circle implements Shape{
private in radius;
public void draw(); }
E.
public class Circle extends Shape{
private in radius;
public void draw(){/* code here */}
}
F.
public abstract class Circle implements Shape{
private in radius;
public void draw(){/* code here */}
}
答案:BE
參考:6-5 繼承、7-6 介面
--------------------------------------------------------
抽象類別
A. public class Circle implements Shape{ //Circle 是一個類別,類別針對Shape這一個抽象類別要用繼承
C. public class Circle extends Shape{
private in radius;
public void draw(); //Circle 是一個類別,即然繼承Shape了就要實做出來...這沒有實做
D. public abstract class Circle implements Shape{ //類別不能實做類別,而是要繼承
F. public abstract class Circle implements Shape{ //類別不能實做類別,而是要繼承
沒有留言:
張貼留言