最新的Oracle Java Standard Edition 6 Programmer Certified Professional - 1Z0-851免費考試真題
Given:
1.import java.util.*;
2.public class WrappedString {
3.private String s;
4.public WrappedString(String s) { this.s = s; }
5.public static void main(String[] args) {
6.HashSet<Object> hs = new HashSet<Object>();
7.WrappedString ws1 = new WrappedString("aardvark");
8.WrappedString ws2 = new WrappedString("aardvark");
9.String s1 = new String("aardvark");
10.String s2 = new String("aardvark");
11.hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);
12.System.out.println(hs.size()); } } What is the result?
1.import java.util.*;
2.public class WrappedString {
3.private String s;
4.public WrappedString(String s) { this.s = s; }
5.public static void main(String[] args) {
6.HashSet<Object> hs = new HashSet<Object>();
7.WrappedString ws1 = new WrappedString("aardvark");
8.WrappedString ws2 = new WrappedString("aardvark");
9.String s1 = new String("aardvark");
10.String s2 = new String("aardvark");
11.hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);
12.System.out.println(hs.size()); } } What is the result?
正確答案: A
Given:
1.public class TestString3 {
2.public static void main(String[] args) {
3.// insert code here
5.System.out.println(s);
6.}
7.}
Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)
1.public class TestString3 {
2.public static void main(String[] args) {
3.// insert code here
5.System.out.println(s);
6.}
7.}
Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)
正確答案: H,I
DRAG DROP
Click the Task button.

Click the Task button.

正確答案:

Given:
11.public static void main(String[] args) {
12.Object obj = new int[] { 1, 2, 3 };
13.int[] someArray = (int[])obj;
14.for (int i : someArray) System.out.print(i + " ");
15.}
What is the result?
11.public static void main(String[] args) {
12.Object obj = new int[] { 1, 2, 3 };
13.int[] someArray = (int[])obj;
14.for (int i : someArray) System.out.print(i + " ");
15.}
What is the result?
正確答案: C
Given:
11.public class Person {
12.private name;
13.public Person(String name) {
14.this.name = name;
15.}
16.public int hashCode() {
17.return 420;
18.}
19.}
Which statement is true?
11.public class Person {
12.private name;
13.public Person(String name) {
14.this.name = name;
15.}
16.public int hashCode() {
17.return 420;
18.}
19.}
Which statement is true?
正確答案: C
Given a pre-generics implementation of a method:
11.public static int sum(List list) {
12.int sum = 0;
13.for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14.int i = ((Integer)iter.next()).intValue();
15.sum += i;
16.}
17.return sum;
18.}
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
11.public static int sum(List list) {
12.int sum = 0;
13.for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14.int i = ((Integer)iter.next()).intValue();
15.sum += i;
16.}
17.return sum;
18.}
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
正確答案: A,B,E
DRAG DROP
Click the Task button.

Click the Task button.

正確答案:

Given a pre-generics implementation of a method:
11.public static int sum(List list) {
12.int sum = 0;
13.for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14.int i = ((Integer)iter.next()).intValue();
15.sum += i;
16.}
17.return sum;
18.}
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
11.public static int sum(List list) {
12.int sum = 0;
13.for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14.int i = ((Integer)iter.next()).intValue();
15.sum += i;
16.}
17.return sum;
18.}
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
正確答案: A,B,E
Given:
11.// insert code here
12.private N min, max;
13.public N getMin() { return min; }
14.public N getMax() { return max; }
15.public void add(N added) {
16.if (min == null || added.doubleValue() < min.doubleValue())
17.min = added;
18.if (max == null || added.doubleValue() > max.doubleValue()) 19. max = added;
20.}
21.}
Which two, inserted at line 11, will allow the code to compile? (Choose two.)
11.// insert code here
12.private N min, max;
13.public N getMin() { return min; }
14.public N getMax() { return max; }
15.public void add(N added) {
16.if (min == null || added.doubleValue() < min.doubleValue())
17.min = added;
18.if (max == null || added.doubleValue() > max.doubleValue()) 19. max = added;
20.}
21.}
Which two, inserted at line 11, will allow the code to compile? (Choose two.)
正確答案: C,D
Given:
31.class Foo {
32.public int a = 3;
33.public void addFive() { a += 5; System.out.print("f "); }
34.}
35.class Bar extends Foo {
36.public int a = 8;
37.public void addFive() { this.a += 5; System.out.print("b " ); }
38.} Invoked with: Foo f = new Bar(); f.addFive(); System.out.println(f.a);
What is the result?
31.class Foo {
32.public int a = 3;
33.public void addFive() { a += 5; System.out.print("f "); }
34.}
35.class Bar extends Foo {
36.public int a = 8;
37.public void addFive() { this.a += 5; System.out.print("b " ); }
38.} Invoked with: Foo f = new Bar(); f.addFive(); System.out.println(f.a);
What is the result?
正確答案: F
Given:
10.class One {
11.void foo() { }
12.}
13.class Two extends One {
14.//insert method here
15.}
Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)
10.class One {
11.void foo() { }
12.}
13.class Two extends One {
14.//insert method here
15.}
Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)
正確答案: C,D,E
DRAG DROP
Click the Task button.

Click the Task button.

正確答案:

Given:
1.class Super {
2.private int a;
3.protected Super(int a) { this.a = a; }
4.} ...
11.class Sub extends Super {
12.public Sub(int a) { super(a); }
13.public Sub() { this.a = 5; }
14.}
Which two, independently, will allow Sub to compile? (Choose two.)
1.class Super {
2.private int a;
3.protected Super(int a) { this.a = a; }
4.} ...
11.class Sub extends Super {
12.public Sub(int a) { super(a); }
13.public Sub() { this.a = 5; }
14.}
Which two, independently, will allow Sub to compile? (Choose two.)
正確答案: D,E
Given:
11.class Converter {
12.public static void main(String[] args) {
13.Integer i = args[0];
14.int j = 12;
15.System.out.println("It is " + (j==i) + " that j==i.");
16.}
17.}
What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?
11.class Converter {
12.public static void main(String[] args) {
13.Integer i = args[0];
14.int j = 12;
15.System.out.println("It is " + (j==i) + " that j==i.");
16.}
17.}
What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?
正確答案: D