1Z0-851 Exam Questions
190 real 1Z0-851 exam questions with expert-verified answers and explanations. Page 1 of 4.
- Question #1
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 =...
- Question #2
A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0, object), but does NOT need to support quick random access. What sup...
- Question #3
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...
- Question #4
Given: import java.util.*; public class Explorer2 { public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Intege...
- Question #5
Given: public class Score implements Comparable<Score> { private int wins, losses; public Score(int w, int l) { wins = w; losses = l; } public int getWins() { return wins; } public...
- Question #6
Given: public class Person { private name; public Person(String name) { this.name = name; } public int hashCode() { return 420; } } Which statement is true?
- Question #7
Given: import java.util.*; public class SortOf { public static void main(String[] args) { ArrayList<Integer> a = new ArrayList<Integer>(); a.add(1); a.add(5); a.add(3); Collections...
- Question #8
Given 11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.)
- Question #9
Given: class Atom { Atom() { System.out.print("atom "); } } class Rock extends Atom { Rock(String type) { System.out.print(type); } } public class Mountain extends Rock { Mountain(...
- Question #10
Click the Exhibit button. Which three statements are true? (Choose three.)
- Question #11
Given: 10. class Line { 11. public class Point { public int x,y;} 12. public Point getPoint() { return new Point(); } 13. } 14. class Triangle { 15. public Triangle() { 16. // inse...
- Question #12
Given: class Alpha { public void foo() { System.out.print("Afoo "); } } public class Beta extends Alpha { public void foo() { System.out.print("Bfoo "); } public static void main(S...
- Question #13
Click the Exhibit button. Which statement is true about the classes and interfaces in the exhibit?
- Question #14
Which two code fragments correctly create and initialize a static array of int elements? (Choose two.)
- Question #15
Given: 09. interface Foo { int bar(); } 10. 11. public class Sprite { 12. public int fubar( Foo foo ) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. //insert code...
- Question #16
Given: class Alligator { public static void main(String[] args) { int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}}; int [][]y = x; System.out.println(y[2][1]); } } What is the result?
- Question #17
Given: 22. StringBuilder sb1 = new StringBuilder("123"); 23. String s1 = "123"; 24. // insert code here 25. System.out.println(sb1 + " " + s1); Which code fragment, inserted at lin...
- Question #18
Given that the current directory is empty, and that the user has read and write permissions, and the following: import java.io.*; public class DOS { public static void main(String[...
- Question #19
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....
- Question #20
Given: 11. String test = "Test A. Test B. Test C."; 12. // insert code here 13. String[] result = test.split(regex); Which regular expression, inserted at line 12, correctly splits...
- Question #21
Given: import java.util.Date; import java.text.DateFormat; 21. DateFormat df; 22. Date date = new Date(); 23. //insert code here 24. String s = df.format(date); Which code fragment...
- Question #22
Given a class Repetition: package utils; public class Repetition { public static String twice(String s) { return s + s; } } and given another class Demo: 01. public class Demo { 02...
- Question #23
A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starti...
- Question #24
Given: 01. interface Animal { void makeNoise(); } 02. class Horse implements Animal { 03. Long weight = 1200L; 04. public void makeNoise() { System.out.println("whinny"); } 05. } 0...
- Question #25
Given classes defined in two different files: package util; public class BitUtils { private static void process(byte[] b) {} } 01. package app; 02. public class SomeApp { 03. publi...
- Question #26
Click the Exhibit button. Given the fully-qualified class names: com.foo.bar.Dog com.foo.bar.blatz.Book com.bar.Car com.bar.blatz.Sun Which graph represents the correct directory s...
- Question #27
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...
- Question #28
Given: public class Pass { public static void main(String [] args) { int x = 5; Pass p = new Pass(); p.doStuff(x); System.out.print(" main x = " + x); } void doStuff(int x) { Syste...
- Question #29
Given: 1. public class GC { 2. private Object o; 3. private void doSomethingElse(Object obj) { o = obj; } 4. public void doSomething() { 5. Object o = new Object(); 6. doSomethingE...
- Question #30
Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ",...
- Question #31
Given: 01. interface A { public void aMethod(); } 02. interface B { public void bMethod(); } 03. interface C extends A,B { public void cMethod(); } 04. class D implements B { 05. p...
- Question #32
Given that: Gadget has-a Sprocket and Gadget has-a Spring and Gadget is-a Widget and Widget has-a Sprocket Which two code fragments represent these relationships? (Choose two.)
- Question #33
A company that makes Computer Assisted Design (CAD) software has, within its application, some utility classes that are used to perform 3D rendering tasks. The company's chief scie...
- Question #34
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
- Question #35
Given: class Foo { public int a = 3; public void addFive() { a += 5; System.out.print("f "); } } class Bar extends Foo { public int a = 8; public void addFive() { this.a += 5; Syst...
- Question #36
Given: class Animal { public String noise() { return "peep"; } } class Dog extends Animal { public String noise() { return "bark"; } } class Cat extends Animal { public String nois...
- Question #37
Given: 01. class Super { 02. private int a; 03. protected Super(int a) { this.a = a; } 04. } 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { th...
- Question #38
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); Syst...
- Question #39
Given: package geometry; public class Hypotenuse { public InnerTriangle it = new InnerTriangle(); class InnerTriangle { public int base; public int height; } } Which statement is t...
- Question #40
Given: 01. public class Hi { 02. void m1() { } 03. protected void() m2 { } 04. } 05. 06. class Lois extends Hi { 07. // insert code here 08. } Which four code fragments, inserted i...
- Question #41
Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
- Question #42
Given: import java.io.IOException; class A { public void process() { System.out.print("A,"); } } 13. class B extends A { 14. public void process() throws IOException { 15. super.pr...
- Question #43
Given: 11. public void go(int x) { 12. assert (x > 0); 13. switch(x) { 14. case 2: ; 15. default: assert false; 16. } 17. } 18. private void go2(int x) { assert (x < 0); } Which st...
- Question #44
Given: 1. public class Breaker2 { 2. static String o = ""; 3. 4. public static void main(String[] args) { 5. z: for (int x = 2; x < 7; x++) { 6. if (x == 3) 7. continue; 8. if (x =...
- Question #45
Given: public static void main(String[] args) { String str = "null"; if (str == null) { System.out.println("null"); } else (str.length() == 0) { System.out.println("zero"); } else...
- Question #46
Given: public class Test { public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.prin...
- Question #47
Given: static void test() throws Error { if (true) throw new AssertionError(); System.out.print("test "); } public static void main(String[] args) { try { test(); } catch (Exceptio...
- Question #48
Given: public class Foo { static int[] a; static { a[0]=2; } public static void main( String[] args ) {} } Which exception or error will be thrown when a programmer attempts to run...
- Question #49
Click the Exhibit button. Given: 25. try { 26. A a = new A(); 27. a.method1(); 28. } catch (Exception e) { 29. System.out.print("an error occurred"); 30. } Which two statements are...
- Question #50
Given: public static void main(String[] args) { for (int i = 0; i <= 10; i++) { if (i > 6) break; } System.out.println(i); } What is the result?