105. 不能被修改的方法 -- final 存取限制
第 12 行就因為 Parent 中已經將 Show() 設定為
final, 所以無法重新定義 , 編譯時會發生錯誤。
▪ 之前已經提過 , 如果為成員變數加上 final 存取控制 ,
也就限制了該成員變數內容無法在設定初值後更改。
▪ 類別也可以加上 final, 表示不允許有子類別。例如
public final class A { }, 則 class B extends A { } 就會
編譯錯誤 。
175. Which one is true ?
A. Print 2.
B. Print 4.
C. Print 8.
D. Compilation fails.
E. An exception is thrown at runtime.
176. 2. Given :
Which two changes should be made to correct the compilation
errors.
A. Insert a super(); into the Child constructor.
B. Insert a super(n); into the Child constructor.
C. Insert a this(); into the Child constructor.
D. Remove the public from all constructors.
E. Change private at line 2 to protected.
F. Change the name at line 2 to name = ""
179. 4. Given:
What is the result?
A. ... @!#
D. Compilation fails.
runtime.
F. ... ~~~
B. ~~~ @!#
C. ~~~ ~~~
E. An exception is thrown at
180.
181. 5. Which three statements concerning is-a and has-a
relationships are true? (Choose three)
A. Inheritance is is-a relationship.
B. Inheritance is has-a relationship.
C. Member variable can be used to implement the is-a
relationship.
D. Member variable can be used to implement the has-a
relationship.
E. Child class is-a parent class.
F. Parent class is-a child class.
G. Parent class has-a child class.
182. 6. Place the Classes in Type column and Relationships in
Relationship column, to match the is-a or has-a
relationships.
186. Which code inserted at line 8 will compile? (Choose all that
apply.)
A. private void print(String s) { }
B. protected void print(String s) { }
C. String print(String x) { }
D. String print(int i) { return "ok"; }
E. void print(String s, String t) { }
F. B print(String z) { }
G. B print(A a) { return (B)a; }
H. Object print(A a) { return a; }
187. 8. Given the following code, place the correct Output Strings
to the Output Sequence:
188.
189.
190. 9. Given:
What is the result?
A. ABC
D. BC
B. ABAC
E. CB
C. BACA
F. CABA
193. 10. Drag and drop the appropriate sentence into the following
empty boxes:
194. Which code inserted at line 7 will compile?(Choose all that
apply.)
A. This() { this.i = 5; }
B. This() { super.i = 5; }
C. This() { super(5); }
D. This() { Super(5); }
E. This() { this(5); }
F. This() { This(5); }