我昨天過了個還算悠閒的日子,早上寫完日記,因著情緒的低落,我打開了電視轉到HBO,拆開餅乾開始吃餅乾看電影XD
因為我會怕胖,所以沒拿太多餅乾,後來餅乾吃完了,但電影還沒演完該怎麼辦呢?我拿出了我之前煮好的水煮蛋慢慢吃,再挑了六顆葡萄慢慢咬......
總之吃到後來我真的覺得不能再吃,也實在吃不下時,我把東西收了收,再度打開電腦,開始與人在網路上聊天邊看HBO
中午吃完午餐後,經過我左思右想,我還是決定這次的小組報告我既然是負責書面報告的,與其一直等待其他組員是否有辦法幫忙列印,到不如我自己把印表機的事情搞定吧!
也因為如此,前前後後我跑了三趟燦坤3C(累到爆),還買了一組墨水(有夠貴千元大鈔就這樣飛了),不過最後電器醫院的員工也教了我一些東西,還幫我把印表機也校正好嘍!(開心)
正所謂有失必有得嘛!反正我的心情變的比較好以後,下午我很自然地又拿起SCJP的考題出來看了,以下就是我昨天遇到的問題,還麻煩各位大大的教導嘍!謝謝^_^
Overriding與Overloading
50.
A programmer needs to create a logging method that can accept an
arbitrary number of arguments. For example, it may be called in these ways:
logIt("log message1");
logIt("log message2","log message3");
logIt("log message4","log message5","log message6");
Which declaration satisfies this requirement?
A. public void logIt(String * msgs)
B. public void logIt(String [] msgs)
C. public void logIt(String... msgs)
D. public void logIt(String msg1, String msg2, String msg3)
這我根本看不懂= ="
106.
Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?
A. Compilation fails because of an error in line 3.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 9.
D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.
E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.
F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.
這題我不懂為何?
197.
What is the result?
A. Value is: 8
B. Compilation fails.
C. Value is: 12
D. Value is: -12
E. The code runs with no output.
F. An exception is thrown at runtime.
這題也是不懂Orz...
204.
這題我不會/___\
222.
Which two statements are true? (Choose two.)
A. An encapsulated, public class promotes re-use.
B. Classes that share the same interface are always tightly encapsulated.
C. An encapsulated class allows subclasses to overload methods, but does NOT allow overriding methods.
D. An encapsulated class allows a programmer to change an implementation without affecting outside code.
太長的述敘嚇到我了Orz...
240.
Given:
11. public class Yikes {
12.
13. public static void go(Long n) {System.out.print("Long ");}
14. public static void go(Short n) {System.out.print("Short ");}
15. public static void go(int n) {System.out.print("int ");}
16. public static void main(String [] args) {
17. short y = 6;
18. long z = 7;
19. go(y);
20. go(z);
21. }
22. }
What is the result?
A. int Long
B. Short Long
C. Compilation fails.
D. An exception is thrown at runtime.
為什麼呢?
263.
Given:
1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
為何不是C呢?
269.
Given:
10. abstract public class Employee {
11. protected abstract double getSalesAmount();
12. public double getCommision() {
13. return getSalesAmount() * 0.15;
14. }
15. }
16. class Sales extends Employee {
17. // insert method here
18. }
Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.)
A. double getSalesAmount() { return 1230.45; }
B. public double getSalesAmount() { return 1230.45; }
C. private double getSalesAmount() { return 1230.45; }
D. protected double getSalesAmount() { return 1230.45; }
這題我還是不行Orz...
300.
Given:
1. public class Blip {
2. protected int blipvert(int x) { return 0; }
3. }
4. class Vert extends Blip {
5. // insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)
A. public int blipvert(int x) { return 0; }
B. private int blipvert(int x) { return 0; }
C. private int blipvert(long x) { return 0; }
D. protected long blipvert(int x) { return 0; }
E. protected int blipvert(long x) { return 0; }
F. protected long blipvert(long x) { return 0; }
G. protected long blipvert(int x, int y) { return 0; }
有沒有真的有那麼多個答案啊Orz...
309.
Given:
1. class SuperClass {
2. public A getA() {
3. return new A();
4. }
5. }
6. class SubClass extends SuperClass {
7. public B getA(){
8. return new B();
9. }
10. }
Which statement is true?
A. Compilation will succeed if A extends B.
B. Compilation will succeed if B extends A.
C. Compilation will always fail because of an error in line 7.
D. Compilation will always fail because of an error in line 8.
我不懂啊!為何我選的那個答案不對?
Interface
41.
What is the result?
A. go in Goban
go in Sente
B. go in Sente
go in Goban
C. go in Goban
go in Sente
D. Compilation fails because of an error in line 17.
我昏了Orz...
44.
Given:
1. public interface A {
2. String DEFAULT_GREETING = "Hello World";
3. public void method1();
4. }
A programmer wants to create an interface called B that has A as its parent.
Which interface declaration is correct?
A. public interface B extends A {}
B. public interface B implements A {}
C. public interface B instanceOf A {}
D. public interface B inheritsFrom A {}
我不懂啊Orz...
48.
Given:
11. public static void parse(String str) {
12. try {
13. float f = Float.parseFloat(str);
14. } catch (NumberFormatException nfe) {
15. f = 0;
16. } finally {
17. System.out.println(f);
18. }
19. }
20. public static void main(String[] args) {
21. parse("invalid");
22. }
What is the result?
A. 0.0
B. Compilation fails.
C. A ParseException is thrown by the parse method at runtime.
D. A NumberFormatException is thrown by the parse method at runtime.
這個老師沒給答案@@"
56.
Given:
1. interface DoStuff2 {
2. float getRange(int low, int high); }
3.
4. interface DoMore {
5. float getAvg(int a, int b, int c); }
6.
7. abstract class DoAbstract implements DoStuff2, DoMore { }
8.
9. class DoStuff implements DoStuff2 {
10. public float getRange(int x, int y) { return 3.14f; } }
11.
12. interface DoAll extends DoMore {
13. float getAvg(int a, int b, int c, int d); }
What is the result?
A. The file will compile without error.
B. Compilation fails. Only line 7 contains an error.
C. Compilation fails. Only line 12 contains an error.
D. Compilation fails. Only line 13 contains an error.
E. Compilation fails. Only lines 7 and 12 contain errors.
F. Compilation fails. Only lines 7 and 13 contain errors.
G. Compilation fails. Lines 7, 12, and 13 contain errors.
為何會是A呢?
116.
Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
D. Compilation of class AImpl will fail because of an error in line 2.
厚~這種寫法很累耶!/___\
Has-a與is-a
5.
Given:
10. interface Jumper { public void jump(); }
...
20. class Animal {}
...
30. class Dog extends Animal {
31. Tail tail;
32. }
...
40. class Beagle extends Dog implements Jumper{
41. public void jump() {}
42. }
...
50. class Cat implements Jumper{
51. public void jump() {}
52. }
Which three are true? (Choose three.)
A. Cat is-a Animal
B. Cat is-a Jumper
C. Dog is-a Animal
D. Dog is-a Jumper
E. Cat has-a Animal
F. Beagle has-a Tail
G. Beagle has-a Jumper
為何要選F?
108.
Which four statements are true? (Choose four.)
A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. The relationship between Movie and Actress is an example of an is-a relationship.
G. An array or a collection can be used to implement a one-to-many has-a relationship.
這個確定不是在考英文?
196.
這題老師也沒給答案,我猜不到啦Orz...
Abstract-class
310.
Given:
11. public abstract class Shape {
12. int x;
13. int y;
14. public abstract void draw();
15. public void setAnchor(int x, int y) {
16. this.x = x;
17. this.y = y;
18. }
19. }
and a class Circle that extends and fully implements the Shape class.
Which is correct?
A. Shape s = new Shape();
s.setAnchor(10,10);
s.draw();
B. Circle c = new Shape();
c.setAnchor(10,10);
c.draw();
C. Shape s = new Circle();
s.setAnchor(10,10);
s.draw();
D. Shape s = new Circle();
s->setAnchor(10,10);
s->draw();
E. Circle c = new Circle();
c.Shape.setAnchor(10,10);
c.Shape.draw();
為何是C?在我猜的答案中就是沒C...
多型
25.
Given:
enum Example { ONE, TWO, THREE }
Which statement is true?
A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be true.
B. The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO) is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HashMap; instead, the programmer must use a java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because enumerated types do NOT implement java.lang.Comparable.
這題我搞不太懂Orz...
121.
這題我錯的有點兇@@"
158.
Given:
11. public enum Title {
12. MR("Mr."), MRS("Mrs."), MS("Ms.");
13. private final String title;
14. private Title(String t) { title = t; }
15. public String format(String last, String first) {
16. return title + " " + first + " " + last;
17. }
18. }
19. public static void main(String[] args) {
20. System.out.println(Title.MR.format("Doe", "John"));
21. }
What is the result?
A. Mr. John Doe
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 20.
我不懂這題A為何會對?
195.
Which statement is true about the set variable on line 12?
A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be
preserved.
B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be
preserved.
C. The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be
preserved.
D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to
be preserved.
我不懂這題為何答案是D而不是B?
以上就這些嘍!感謝大大們的教導^_^
留言列表