Scjp 6.0 _ Java _ Level 2

10 Questions | Total Attempts: 54

SettingsSettingsSettings
Please wait...
Java Quizzes & Trivia

歡迎來挑戰 SCJP 6. 0_JAVA_ level 2


Questions and Answers
  • 1. 
    Given: class One {     void foo() {     } } class Two extends One {     // insert method here } Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.) 
    • A. 

      Int foo(){/* more code here */}

    • B. 

      Void foo(){/* more code here */}

    • C. 

      Public void foo(){/* more code here */}

    • D. 

      Private void foo(){/* more code here */}

    • E. 

      Protected void foo(){/* more code here */}

  • 2. 
    Given: class X {     X() {         System.out.print(1);     }     X(int x) {         this();         System.out.print(2);     } } public class Y extends X {     Y() {         super(6);         System.out.print(3);     }     Y(int y) {         this();         System.out.println(4);     }     public static void main(String[] a) {         new Y(5);     } } What is the result? 
    • A. 

      13

    • B. 

      134

    • C. 

      1234

    • D. 

      2134

    • E. 

      2143

    • F. 

      4321

  • 3. 
    Given: 1. public class A{ 2.     public void doit(){ 3. } 4. public String doit(){ 5.     return "a"; 6. } 7. public double doit(int x){ 8.     return 1.0; 9. } 10.} What is the result? 
    • A. 

      An exception is thrown at runtime.

    • B. 

      Compilation fails because of an error in line 7.

    • C. 

      Compilation fails because of an error in line 4.

    • D. 

      Compilation succeeds and no runtime errors with class A occur.

  • 4. 
    Given: public class SimpleCalc {     public int value;     public void calculate() {         value += 7;     } } And: public class MultiCalc extends SimpleCalc {     public void calculate() {         value -= 3;     }     public void calculate(int multiplier) {         calculate();         super.calculate();         value *= multiplier;     }     public static void main(String[] args) {         MultiCalc calculator = new MultiCalc();         calculator.calculate(2);         System.out.println("Value is: " + calculator.value);     } } 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.

  • 5. 
    Given: public class Base {     public static final String FOO = "foo";     public static void main(String[] args) {         Base b = new Base();         Sub s = new Sub();         System.out.print(Base.FOO);         System.out.print(Sub.FOO);         System.out.print(b.FOO);         System.out.print(s.FOO);         System.out.print(((Base) s).FOO);     } } class Sub extends Base {     public static final String FOO = "bar"; } What is the result? 
    • A. 

      Foofoofoofoofoo

    • B. 

      Foobarfoobarbar

    • C. 

      Foobarfoofoofoo

    • D. 

      Foobarfoobarfoo

    • E. 

      Barbarbarbarbar

    • F. 

      Foofoofoobarbar

    • G. 

      Foofoofoobarfoo

  • 6. 
    Given: class Mammal { } class Raccoon extends Mammal {     Mammal m = new Mammal(); } class BabyRaccoon extends Mammal { } Which four statments are true? (Choose four.) 
    • A. 

      Raccoon is-a Mammal.

    • B. 

      Raccoon has-a Mammal.

    • C. 

      BabyRaccoon is-a Mammal.

    • D. 

      BabyRaccoon is-a Raccoon.

    • E. 

      BabyRaccoon has-a Mammal.

    • F. 

      BabyRaccoon is-a BabyRaccoon.

  • 7. 
    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.

  • 8. 
    Given: public class Hello {     String title;     int value;     public Hello() {         title += " World";     }     public Hello(int value) {         this.value = value;         title = "Hello";         Hello();     } } And: Hello c = new Hello(5); System.out.print(c.title); What is the result? 
    • A. 

      Hello

    • B. 

      Hello World

    • C. 

      Compilation fails.

    • D. 

      Hello World 5

    • E. 

      The code runs with no output.

    • F. 

      An exception is thrown at runtime.

  • 9. 
    Given: public class ItemTest {     private final int id;     public ItemTest(int id) {         this.id = id;     }     public void updateId(int newId) {         id = newId;     }     public static void main(String[] args) {         ItemTest fa = new ItemTest(42);         fa.updateId(69);         System.out.println(fa.id);     } } Which four statments are true? 
    • A. 

      Compilation fails.

    • B. 

      An exception is thrown at runtime.

    • C. 

      The attribute id in the ItemTest object remains unchanged.

    • D. 

      The attribute id in the ItemTest object is modified to the new value.

    • E. 

      A new ItemTest object is created with the preferred value in the id attribute.

  • 10. 
    Given: class Foo {     private int x;     public Foo(int x) {         this.x = x;     }     public void setX(int x) {         this.x = x;     }     public int getX() {         return x;     } } public class Gamma {     static Foo fooBar(Foo foo) {         foo = new Foo(100);         return foo;     }     public static void main(String[] args) {         Foo foo = new Foo(300);         System.out.print(foo.getX() + "-");         Foo fooFoo = fooBar(foo);         System.out.print(foo.getX() + "-");         System.out.print(fooFoo.getX() + "-");         foo = fooBar(fooFoo);         System.out.print(foo.getX() + "-");         System.out.print(fooFoo.getX());     } } What is the output? 
    • A. 

      300-100-100-100-100

    • B. 

      300-300-100-100-100

    • C. 

      300-300-300-100-100

    • D. 

      300-300-300-300-100

Back to Top Back to top