为了账号安全,请及时绑定邮箱和手机立即绑定

ocjp认证试题

标签:
面试

QUESTION 177 Given:

  1. class TestException extends Exception { }

  2. class A {

  3. public String sayHello(String name) throws TestException {

  4. if(name == null) throw new TestException();

  5. return "Hello " + name;

  6. }

  7. }

  8. public class TestA {

  9. public static void main(String[] args) {

  10. new A().sayHello("Aiko");

  11. }

  12. }

Whichstatement is true?

A.   Compilation succeeds.

B.   Class A does not compile.

C.   The method declared on line 9 cannot be modified to throwTestException.

D.   TestA compiles if line 10 is enclosed in a try/catch blockthat catches TestException.

Answer: D

Section: (none)

Explanation/Reference:Explanation:

QUESTION 178 Given:

  1. public static void main(String[] args) {

  2. for (int i = 0; i <= 10; i++) {

  3. if (i > 6) break;

  4. }

  5. System.out.println(i);

  6. }

Whatis the result?

A.   6

B.   7

C.   10

D.   11

E.   Compilation fails.

F.    An exception is thrown at runtime.

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 179 Given:

  1. public class Breaker {

  2. static String o = "";

  3. public static void main(String[] args) {

  4. z:

  5. o = o + 2;

  6. for(int x = 3; x < 8; x++) {

  7. if(x==4) break;

  8. if(x==6) break z;

  9. o = o + x;

  10. }

  11. System.out.println(o);

  12. }

  13. }

Whatis the result?

A.   23

B.   234C. 235

D. 2345 E. 2357

F.    23457

G.   Compilation fails.

Answer: G

Section: (none)

Explanation/Reference:Explanation:

QUESTION 180 Given:

  1. class A {

  2. void foo() throws Exception { throw new Exception(); }

  3. }

  4. class SubB2 extends A {

  5. void foo() { System.out.println("B "); }

  6. }

  7. class Tester {

  8. public static void main(String[] args) {

  9. A a = new SubB2();

  10. a.foo();

  11. }

  12. }

Whatis the result?

A.   B

B.   B, followed by an Exception.

C.   Compilation fails due to an error on line 9.

D.   Compilation fails due to an error on line 14.

E.   An Exception is thrown with no other output.

Answer: D

Section: (none)

Explanation/Reference:Explanation:

QUESTION 181 Given:

  1. public static void main(String[] args) {

  2. String str = "null";

  3. if (str == null) {

  4. System.out.println("null");

  5. } else (str.length() == 0) {

  6. System.out.println("zero");

  7. } else {

  8. System.out.println("some");

  9. }

  10. }

Whatis the result?

A.   null

B.   zero

C.   some

D.   Compilation fails.

E.   An exception is thrown at runtime.

Answer: D

Section: (none)

Explanation/Reference:Explanation:

QUESTION182 Given:

  1. public class Mule {

  2. public static void main(String[] args) {

  3. boolean assert = true;

  4. if(assert) {

  5. System.out.println("assert is true");

  6. }

  7. }

  8. }

Whichcommand-line invocations will compile?

A.   javac Mule.java

B.   javac -source 1.3 Mule.javaC. javac-source 1.4 Mule.java

D. javac -source 1.5 Mule.java

Answer: B

Section: (none)

Explanation/Reference:Explanation:

QUESTION 183 Given:

  1. static void test() {

  2. try {

  3. String x = null;

  4. System.out.print(x.toString() + " ");

  5. }

  6. finally { System.out.print("finally "); }

  7. }

  8. public static void main(String[] args) {

  9. try { test(); }

  10. catch (Exception ex) { System.out.print("exception"); }

  11. }

Whatis the result?

A.   null

B.   finally

C.   null finallyD. Compilation fails.

E.finally exception

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 184 Given:

  1. public class Boxer1{

  2. Integer i;

  3. int x;

  4. public Boxer1(int y) {

  5. x = i+y;

  6. System.out.println(x);

  7. }

  8. public static void main(String[] args) {

  9. new Boxer1(new Integer(4));

  10. }

  11. }

Whatis the result?

A.   The value "4" is printed at the command line.

B.   Compilation fails because of an error in line 5.C.Compilation fails because of an error in line 9.

D.   A NullPointerException occurs at runtime.

E.   A NumberFormatException occurs at runtime.

F.    An IllegalStateException occurs at runtime.

Answer: D

Section: (none)

Explanation/Reference:Explanation:

QUESTION 185 Which two codefragments are most likely to cause a StackOverflowError? (Choose two.)

A. int []x = {1,2,3,4,5}; for(int y = 0; y < 6; y++)System.out.println(x[y]); B. static int[] x = {7,6,5,4}; static { x[1] = 8;x[4] = 3; }

C.    for(int y = 10; y < 10; y++)doStuff(y);

D.    void doOne(int x) { doTwo(x); }void doTwo(int y) { doThree(y); } voiddoThree(int z) { doTwo(z); }

E.   for(int x = 0; x < 1000000000; x++)doStuff(x);

F.    void counter(int i) { counter(++i); }

Answer: DF

Section: (none)

Explanation/Reference:Explanation:

QUESTION 186 Given:

  1. static void test() throws RuntimeException {

  2. try {

  3. System.out.print("test ");

  4. throw new RuntimeException();

  5. }

  6. catch (Exception ex) { System.out.print("exception"); }

  7. }

  8. public static void main(String[] args) {

  9. try { test(); }

  10. catch (RuntimeException ex) { System.out.print("runtime"); }

  11. System.out.print("end ");

  12. }

Whatis the result?

A. test end B.Compilation fails.

C.   test runtime end

D.   test exception end

E.   A Throwable is thrown by main at runtime.

Answer: D

Section: (none)

Explanation/Reference:Explanation:

QUESTION 187 Given:

  1. public static void main(String[] args) {

  2. Integer i = new Integer(1) + new Integer(2);

  3. switch(i) {

  4. case 3: System.out.println("three"); break;

  5. default: System.out.println("other"); break;

  6. }

  7. }

Whatis the result?

A.   three

B.   other

C.   An exception is thrown at runtime.

D.   Compilation fails because of an error on line 12.E.Compilation fails because of an error on line 13. F. Compilation fails becauseof an error on line 15.

Answer: A

Section: (none)

Explanation/Reference:Explanation:

QUESTION 188 Given:

  1. class Money {

  2. private String country = "Canada";

  3. public String getC() { return country; }

  4. }

  5. class Yen extends Money {

  6. public String getC() { return super.country; }

  7. }

  8. public class Euro extends Money {

  9. public String getC(int x) { return super.getC(); }

  10. public static void main(String[] args) {

  11. System.out.print(new Yen().getC() + " " + newEuro().getC());

  12. }

  13. }

Whatis the result?

A.   Canada

B.   null CanadaC. Canada null

D.   Canada Canada

E.   Compilation fails due to an error on line 26.F. Compilationfails due to an error on line 29.

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 189 Given:

  1. class ClassA {}

  2. class ClassBextends ClassA {} 13. class ClassC extends ClassA {} and:

  3. ClassA p0 = new ClassA();

  4. ClassB p1 = new ClassB();

  5. ClassC p2 = new ClassC();

  6. ClassA p3 = new ClassB();

  7. ClassA p4 = new ClassC();

Whichthree are valid? (Choose three.)

A. p0 = p1; B. p1= p2; C. p2 = p4;

D.   p2 = (ClassC)p1;

E.   p1 = (ClassB)p3;

F.    p2 = (ClassC)p4;

Answer: AEF

Section: (none)

Explanation/Reference:Explanation:

QUESTION 190 Which threestatements are true? (Choose three.)

A.   A final method in class X can be abstract if and only if Xis abstract.

B.   A protected method in class X can be overridden by anysubclass of X.

C.   A private static method can be called only within otherstatic methods in class X.

D.   A non-static public final method in class X can beoverridden in any subclass of X.

E.   A public static method in class X can be called by a subclassof X without explicitly referencing theclass X.

F.    A method with the same signature as a private final methodin class X can be implemented in asubclass of X.

G.   A protected method in class X can be overridden by asubclass of X only if the subclass is in the samepackage as X.

Answer: BEF

Section: (none)

Explanation/Reference:Explanation:

QUESTION 191 Given:

  1. interface A { void x(); }

  2. class B implements A { public void x() {} public void y() {}}

  3. class C extends B { public void x() {} }

And:

  1. java.util.List<A> list = newjava.util.ArrayList<A>();

  2. list.add(new B());

  3. list.add(new C());

  4. for (A a : list) {

  5. a.x();

  6. a.y();

  7. }

Whatis the result?

A.   The code runs with no output.

B.   An exception is thrown at runtime.

C.   Compilation fails because of an error in line 20.D.Compilation fails because of an error in line 21. E. Compilation fails becauseof an error in line 23. F. Compilation fails because of an error in line 25.

Answer: F

Section: (none)

Explanation/Reference:Explanation:

QUESTION192 Given:

  1. package test;2.

  2. class Target {

  3. public String name = "hello";

  4. }

Whatcan directly access and change the value of the variable name?

A.   any class

B.   only the Target class

C.   any class in the test package

D.   any class that extends Target

Answer: C

Section: (none)

Explanation/Reference:Explanation:

QUESTION 194

Ateam of programmers is involved in reviewing a proposed design for a newutility class. After some discussion, they realize that the current designallows other classes to access methods in the utility class that should beaccessible only to methods within the utility class itself. What design issuehas the team discovered?

A.   Tight coupling

B.   Low cohesion

C.   High cohesion

D.   Loose coupling

E.   Weak encapsulation

F.    Strong encapsulation

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 195 Given:

  1. class Thingy { Meter m = new Meter(); }

  2. class Component { void go() {System.out.print("c"); } }

  3. class Meter extends Component { void go() {System.out.print("m"); } }


  4. class DeluxeThingy extends Thingy {

  5. public static void main(String[] args) {

  6. DeluxeThingy dt = new DeluxeThingy();

  7. dt.m.go();

  8. Thingy t = new DeluxeThingy();

  9. t.m.go();

  10. }

  11. }

Whichtwo are true? (Choose two.)

A.   The output is mm.

B.   The output is mc.

C.   Component is-a Meter.

D.   Component has-a Meter.

E.   DeluxeThingy is-a Component.

F.    DeluxeThingy has-a Component.

Answer: AF

Section: (none)

Explanation/Reference:Explanation:

QUESTION 196

Given:

10.interface Jumper { public void jump(); } ...

20.class Animal {} ...

  1. class Dog extends Animal {

  2. Tail tail; 32. } ...

  3. class Beagle extends Dog implements Jumper{

  4. public void jump() {}

  5. } ...

  6. class Cat implements Jumper{

  7. public void jump() {}

  8. }

Whichthree are true? (Choose three.)

A.   Cat is-a Animal

B.   Cat is-a JumperC. Dog is-a Animal

D.   Dog is-a Jumper

E.   Cat has-a Animal

F.    Beagle has-a Tail

G.   Beagle has-a Jumper

Answer: BCF

Section: (none)

QUESTION 198 Given a validDateFormat object named df, and

  1. Date d = new Date(0L);

  2. String ds = "December 15, 2004";

  3. // insert code here What updates d's value with the daterepresented by ds?

A.   18. d = df.parse(ds);

B.   18. d = df.getDate(ds);

C.   18. try {

  1. d = df.parse(ds);

  2. } catch(ParseException e) { }; D. 18. try {

  3. d = df.getDate(ds);

  4. } catch(ParseException e) { };

Answer: C

Section: (none)

Explanation/Reference:Explanation:

QUESTION 199

Whichtwo scenarios are NOT safe to replace a StringBuffer object with aStringBuilder object? (Choose two.)

A.   When using versions of Java technology earlier than 5.0.

B.   When sharing a StringBuffer among multiple threads.

C.   When using the java.io class StringBufferInputStream.

D.   When you plan to reuse the StringBuffer to build more thanone string.

Answer: AB

Section: (none)

Explanation/Reference:Explanation:

QUESTION200 Given:

  1. String test = "a1b2c3";

  2. String[] tokens = test.split("\d");

  3. for(String s: tokens) System.out.print(s + " ");

Whatis the result?

A.   a b c

B.   1 2 3

C.   a1b2c3

D.   a1 b2 c3

E.   Compilation fails.

F.    The code runs with no output.

G.   An exception is thrown at runtime.

Answer: A

Section: (none)

Explanation/Reference:

QUESTION 201 Given:

  1. public class TestString3 {

  2. public static void main(String[] args) {

  3. // insert code here

  4. System.out.println(s);

  5. }

  6. }

Whichtwo code fragments, inserted independently at line 3, generate the output 4247?(Choose two.)

A.   String s = "123456789";s =(s-"123").replace(1,3,"24") - "89";

B.   StringBuffer s = new StringBuffer("123456789");C.delete(0,3).replace(1,3,"24").delete(4,6);

D.   StringBuffer s = new StringBuffer("123456789");

E.   substring(3,6).delete(1,3).insert(1, "24");

F.    StringBuilder s = newStringBuilder("123456789");G. substring(3,6).delete(1,2).insert(1,"24");

H.   StringBuilder s = new StringBuilder("123456789");

I.      delete(0,3).delete(1,3).delete(2,5).insert(1,"24");

Answer: BE

Section: (none)

Explanation/Reference:Explanation:

QUESTION 202 Given:

  1. String test = "Test A. Test B. Test C.";

  2. // insert code here

  3. String[] result = test.split(regex);

Whichregular expression, inserted at line 12, correctly splits test into "TestA", "Test B", and "Test C"?

A.   String regex = "";

B.   String regex = " ";

C.   String regex = ".*";

D.   String regex = "\s";

E.   String regex = "\.\s*";

F.    String regex = "\w[ .] +";

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 203 Which statement istrue?

A.   A class's finalize() method CANNOT be invoked explicitly.

B.   super.finalize() is called implicitly by any overridingfinalize() method.

C.   The finalize() method for a given object is called no morethan once by the garbage collector.

D.   The order in which finalize() is called on two objects isbased on the order in which the two objectsbecame finalizable.

Answer: C

Section: (none)

Explanation/Reference:Explanation:

QUESTION 204 Given:

  1. public class ItemTest {

  2. private final int id;

  3. publicItemTest(int id) { this.id = id; } 14. public void updateId(int newId) { id =newId; }


  4. public static void main(String[] args) {

  5. ItemTest fa = new ItemTest(42);

  6. fa.updateId(69);

  7. System.out.println(fa.id);

  8. }

  9. }

Whatis the result?

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 thenew value.

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

Answer: A

Section: (none)

Explanation/Reference:Explanation:

QUESTION 205 Given:

  1. interface DeclareStuff {

  2. public static final int EASY = 3;

  3. void doStuff(int t); }

  4. public class TestDeclare implements DeclareStuff {

  5. public static void main(String [] args) {

  6. int x = 5;

  7. new TestDeclare().doStuff(++x);

  8. }

  9. void doStuff(int s) {

  10. s += EASY + ++s;

  11. System.out.println("s " + s);

  12. }

  13. }

Whatis the result?

A.s 14 B. s 16 C. s 10

D.   Compilation fails.

E.   An exception is thrown at runtime.

Answer: D

Section: (none)

QUESTION 207 Given:

  1. public class Commander {

  2. public static void main(String[] args) {

  3. String myProp = / insert code here /

  4. System.out.println(myProp);

  5. }

  6. }and the commandline:

java-Dprop.custom=gobstopper Commander Which two, placed on line 13, will producethe output gobstopper? (Choose two.)

A.   System.load("prop.custom");

B.   System.getenv("prop.custom");

C.   System.property("prop.custom");

D.   System.getProperty("prop.custom");

E.   System.getProperties().getProperty("prop.custom");

Answer: DE

Section: (none)

Explanation/Reference:Explanation:

QUESTION 208 Given:

  1. interface DoStuff2 {

  2. float getRange(int low, int high); }


  3. interface DoMore {

  4. float getAvg(int a, int b, int c); }


7.abstract class DoAbstract implements DoStuff2, DoMore { }

8.

  1. class DoStuffimplements DoStuff2 { 10. public float getRange(int x, int y) { return 3.14f; }}


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

Answer: A

Section: (none)

Explanation/Reference:Explanation:

QUESTION 209 Given:

  1. interface Fish { }

  2. class Perch implements Fish { }

  3. class Walleye extends Perch { }

  4. class Bluegill { }

  5. public class Fisherman {

  6. public static void main(String[] args) {

  7. Fish f = new Walleye();

  8. Walleye w = new Walleye();

  9. Bluegill b = new Bluegill();

  10. if(f instanceof Perch) System.out.print("f-p ");

  11. if(w instanceof Fish) System.out.print("w-f ");

  12. if(b instanceof Fish) System.out.print("b-f ");

  13. }

  14. }

Whatis the result?

A.   w-f

B.   f-p w-f

C.   w-f b-f

D.   f-p w-f b-f

E.   Compilation fails.

F.    An exception is thrown at runtime.

Answer: B

Section: (none)

QUESTION 211 Given:

1.package com.company.application;

2.

  1. public class MainClass {

  2. public static void main(String[] args) {}

  3. }

AndMainClass exists in the /apps/com/company/application directory. Assume theCLASSPATH environment variable is set to "." (current directory).Which two java commands entered at the command line will run MainClass? (Choosetwo.)

A.   java MainClass if run from the /apps directory

B.   java com.company.application.MainClass if run from the /appsdirectory

C.   java -classpath /apps com.company.application.MainClass ifrun from any directory

D.   java -classpath . MainClass if run from the/apps/com/company/application directory

E.   java -classpath /apps/com/company/application:. MainClass ifrun from the /apps directory

F.    java com.company.application.MainClass if run from the/apps/com/company/application directory

Answer: BC

Section: (none)

Explanation/Reference:Explanation:

QUESTION 212 Given:

  1. import java.util.*;

  2. public class Explorer2 {

  3. public static void main(String[] args) {

  4. TreeSet<Integer> s = new TreeSet<Integer>();

  5. TreeSet<Integer> subs = new TreeSet<Integer>();

  6. for(int i = 606; i < 613; i++)

  7. if(i%2 == 0) s.add(i);

  8. subs = (TreeSet)s.subSet(608, true, 611, true);

  9. s.add(629);

  10. System.out.println(s + " " + subs);

  11. }

  12. }

Whatis the result?

A.   Compilation fails.

B.   An exception is thrown at runtime.

C.   [608, 610, 612, 629] [608, 610]

D.   [608, 610, 612, 629] [608, 610, 629]E. [606, 608, 610, 612,629] [608, 610]

F.[606, 608, 610, 612, 629] [608, 610, 629]

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 213 Given that theelements of a PriorityQueue are ordered according to natural ordering, and:

  1. import java.util.*;

  2. public class GetInLine {

  3. public static void main(String[] args) {

  4. PriorityQueue<String> pq = newPriorityQueue<String>();

  5. pq.add("banana");

  6. pq.add("pear");

  7. pq.add("apple");

  8. System.out.println(pq.poll() + " " + pq.peek());

  9. }

  10. }

Whatis the result?

A.   apple pear

B.   banana pear

C.   apple apple

D.   apple banana

E.   banana banana

Answer: D

Section: (none)

Explanation/Reference:Explanation:

QUESTION 214 Given apre-generics implementation of a method:

  1. public static int sum(List list) {

  2. int sum = 0;

  3. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {

  4. int i = ((Integer)iter.next()).intValue();

  5. sum += i;

  6. }

  7. return sum;

  8. }

Whatthree changes allow the class to be used with generics and avoid an uncheckedwarning? (Choose three.)

A.   Remove line 14.

B.   Replace line 14 with "int i = iter.next();".

C.   Replace line 13 with "for (int i : intList) {".

D.   Replace line 13 with "for (Iterator iter : intList){".

E.   Replace the method declaration with"sum(List<int> intList)".

F.    Replace the method declaration with"sum(List<Integer> intList)".

Answer: ACF

Section: (none)

Explanation/Reference:Explanation:

QUESTION 215 Given:

  1. HashMap props = new HashMap();

  2. props.put("key45", "some value");

  3. props.put("key12", "some other value");

  4. props.put("key39", "yet another value");

  5. Set s = props.keySet();

  6. // insert code here What, inserted at line 39, will sort thekeys in the props HashMap?

A.   Arrays.sort(s);

B.   s = new TreeSet(s);

C.   Collections.sort(s);

D.   s = new SortedSet(s);

Answer: B

Section: (none)

Explanation/Reference:Explanation:

QUESTION 216 Given:

  1. public class Person {

  2. private String name;

  3. public Person(String name) {

  4. this.name = name;

  5. }

  6. public boolean equals(Object o) {

  7. if ( ! ( o instanceof Person) ) return false;

  8. Person p = (Person) o;

  9. return p.name.equals(this.name);

  10. }

  11. }

Whichstatement is true?

A.   Compilation fails because the hashCode method is notoverridden.

B.   A HashSet could contain multiple Person objects with thesame name.

C.   All Person objects will have the same hash code because thehashCode method is not overridden.

D.   If a HashSet contains more than one Person object withname="Fred", then removing another Person,also withname="Fred", will remove them all.

Answer: B

Section: (none)

Explanation/Reference:Explanation:

QUESTION 217 Given:

  1. import java.util.*;

  2. public class Hancock {

  3. // insert code here

  4. list.add("foo");

  5. }

  6. }

Whichtwo code fragments, inserted independently at line 5, will compile withoutwarnings? (Choose two.)

A.   public void addStrings(List list) {

B.   public void addStrings(List<String> list) {

C.   public void addStrings(List<? super String> list) {

D.   public void addStrings(List<? extends String> list) {

Answer: BC

Section: (none)

Explanation/Reference:Explanation:

QUESTION 218 Given:

  1. public class Threads4 {

  2. public static void main (String[] args) {

  3. new Threads4().go();

  4. }

  5. public void go() {

  6. Runnable r = new Runnable() {

  7. public void run() {

  8. System.out.print("foo");

  9. }

  10. };

  11. Thread t = new Thread(r);

  12. t.start();

  13. t.start();

  14. }

  15. }

Whatis the result?

A.   Compilation fails.

B.   An exception is thrown at runtime.

C.   The code executes normally and prints "foo".

D.   The code executes normally, but nothing is printed.

Answer: B

Section: (none)

Explanation/Reference:Explanation:

QUESTION 219 Given:

  1. public class TestOne {

  2. public static void main (String[] args) throws Exception {

  3. Thread.sleep(3000);

  4. System.out.println("sleep");

  5. }

  6. } What is the result?

A.   Compilation fails.

B.   An exception is thrown at runtime.

C.   The code executes normally and prints "sleep".

D.   The code executes normally, but nothing is printed.

Answer: C

Section: (none)

Explanation/Reference:Explanation:

QUESTION 220 Given:

  1. public class TestSeven extends Thread {

  2. private static int x;

  3. public synchronized void doThings() {

  4. int current = x;

  5. current++;

  6. x = current;

  7. }

  8. public void run() {

  9. doThings();

  10. }

11.}

Whichstatement is true?

A.   Compilation fails.

B.   An exception is thrown at runtime.

C.   Synchronizing the run() method would make the classthread-safe.

D.   The data in variable "x" are protected fromconcurrent access problems.

E.   Declaring the doThings() method as static would make theclass thread-safe.

F.    Wrapping the statements within doThings() in asynchronized(new Object()) { } block would make theclass thread-safe.

Answer: E

Section: (none)

Explanation/Reference:Explanation:

QUESTION 221 Which two codefragments will execute the method doStuff() in a separate thread? (Choose two.)

A.   new Thread() {

publicvoid run() { doStuff(); }

};

B.   new Thread() {

publicvoid start() { doStuff(); }

};

C.   new Thread() {

publicvoid start() { doStuff(); }

}.run();

D.   new Thread() {

publicvoid run() { doStuff(); }

}.start();

E.   new Thread(new Runnable() {public void run() { doStuff(); }

}).run();

F.    new Thread(new Runnable() {public void run() { doStuff(); }

}).start();

Answer: DF

Section: (none)

Explanation/Reference:Explanation:

QUESTION 222 Given:

  1. public static void main(String[] args) {

  2. Object obj = new int[] { 1, 2, 3 };

  3. int[] someArray = (int[])obj;

  4. for (int i : someArray) System.out.print(i + " ");

  5. }

Whatis the result?

A.   1 2 3

B.   Compilation fails because of an error in line 12.C.Compilation fails because of an error in line 13.

D.   Compilation fails because of an error in line 14.

E.   A ClassCastException is thrown at runtime.

Answer: A

Section: (none)

Explanation/Reference:Explanation:

QUESTION 223 Given:

  1. interface Data { public void load(); }

  2. abstract class Info { public abstract void load(); }

Whichclass correctly uses the Data interface and Info class?

A.   public class Employee extends Info implements Data { publicvoid load() { /do something/ }

}

B.   public class Employee implements Info extends Data { publicvoid load() { /do something/ }

}

C.   public class Employee extends Info implements Data { publicvoid load(){ /do something/ }public void Info.load(){ /do something/ }

}

D.   public class Employee implements Info extends Data { publicvoid Data.load(){ /do something/ }public void load(){ /do something/ }

}

E.   public class Employee implements Info extends Data { publicvoid load(){ /do something/ }public void Info.load(){ /do something/ }

}

F.    public class Employee extends Info implements Data{publicvoid Data.load() { /do something/ }

publicvoid Info.load() { /do something/ }

}

Answer: A

Section: (none)

Explanation/Reference:Explanation:

QUESTION 224 Given:

  1. public static void parse(String str) {

  2. try {

  3. float f = Float.parseFloat(str);

  4. } catch (NumberFormatException nfe) {

  5. f = 0;

  6. } finally {

  7. System.out.println(f);

  8. }

  9. }

  10. public static void main(String[] args) {

  11. parse("invalid");

  12. }

Whatis 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 atruntime.

Answer: B

Section: (none)

Explanation/Reference:Explanation:

QUESTION 225

Given 11. public interface Status {

  1. / insert code here / int MY_VALUE = 10;

  2. }

Whichthree are valid on line 12? (Choose three.)

A.   final

B.   static

C.   native

D.   public

E.   private

F.    abstract

G.   protected

Answer: ABD

Section: (none)

Explanation/Reference:Explanation:

QUESTION 226 Given:

  1. interface TestA { String toString(); }

  2. public class Test {

  3. public static void main(String[] args) {

  4. System.out.println(new TestA() {

  5. public String toString() { return "test"; }

  6. });

  7. }

  8. }

Whatis the result?

A. test B. null

C.   An exception is thrown at runtime.

D.   Compilation fails because of an error in line 1.E.Compilation fails because of an error in line 4. F. Compilation fails becauseof an error in line 5.

Answer: A

Section: (none)

Explanation/Reference:Explanation:

QUESTION 227 Given:

11.public interface A { public void m1(); }

12.

  1. class B implements A { }

  2. class C implements A { public void m1() { } }

  3. class D implements A { public void m1(int x) { } }

  4. abstract class E implements A { }

  5. abstract class Fimplements A { public void m1() { } } 18. abstract class G implements A {public void m1(int x) { } }

Whatis the result?

A.   Compilation succeeds.

B.   Exactly one class does NOT compile.

C.   Exactly two classes do NOT compile.

D.   Exactly four classes do NOT compile.

E.   Exactly three classes do NOT compile.

Answer: C

Section: (none)

Explanation/Reference:Explanation:

QUESTION 228 Given:

  1. abstract class C1 {

  2. public C1() { System.out.print(1); }

  3. }

  4. class C2 extends C1 {

  5. public C2() { System.out.print(2); }

  6. }

  7. class C3 extends C2 {

  8. public C3() { System.out.println(3); }

  9. }

  10. public class Ctest {

  11. public static void main(String[] a) { new C3(); }

  12. }

Whatis the result?

A.   3

B.   23C. 32

D.   123

E.   321

F.    Compilation fails.

G.   An exception is thrown at runtime.

Answer: D

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消