1Z0-851 Exam Questions
190 real 1Z0-851 exam questions with expert-verified answers and explanations. Page 4 of 4.
- Question #200
Given: String test = "a1b2c3"; String[] tokens = test.split("\\d"); for(String s: tokens) System.out.print(s + " "); What is the result?
- Question #201
Given: 01. public class TestString3 { 02. public static void main(String[] args) { 03. // insert code here 04. System.out.println(s); 05. } 06. } Which two code fragments, inserted...
- Question #203
Which statement is true?
- Question #206
Click the Exhibit button. Which three code fragments, added individually at line 29, produce the output 100? (Choose three.)
- Question #208
Given: interface DoStuff2 { float getRange(int low, int high); } interface DoMore { float getAvg(int a, int b, int c); } abstract class DoAbstract implements DoStuff2, DoMore { } 0...
- Question #209
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 #215
Given: 34. HashMap props = new HashMap(); 35. props.put("key45", "some value"); 36. props.put("key12", "some other value"); 37. props.put("key39", "yet another value"); 38. Set s =...
- Question #216
Given: public class Person { private String name; public Person(String name) { this.name = name; } public boolean equals(Object o) { if ( ! ( o instanceof Person) ) return false; P...
- Question #217
Given: import java.util.*; public class Hancock { // insert code here list.add("foo"); } } Which two code fragments, inserted independently at line 5, will compile without warnings...
- Question #218
Given: public class Threads4 { public static void main (String[] args) { new Threads4().go(); } public void go() { Runnable r = new Runnable() { public void run() { System.out.prin...
- Question #220
Given: public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings()...
- Question #222
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 + " ");...
- Question #223
Given: interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?
- Question #224
Given: public static void parse(String str) { try { float f = Float.parseFloat(str); } catch (NumberFormatException nfe) { f = 0; } finally { System.out.println(f); } } public stat...
- Question #225
Given: public class LineUp { public static void main(String[] args) { double d = 12.345; // insert code here } } Which code fragment, inserted at line 4, produces the output | 12.3...
- Question #226
Given: interface TestA { String toString(); } public class Test { public static void main(String[] args) { System.out.println(new TestA() { public String toString() { return "test"...
- Question #229
Click the Exhibit button. What is the result?
- Question #231
Given: class One { public One foo() { return this; } } class Two extends One { public One foo() { return this; } } class Three extends Two { // insert method here } Which two metho...
- Question #235
Given: 04. class Payload { 05. private int weight; 06. public Payload (int w) { weight = w; } 07. public void setWeight(int w) { weight = w; } 08. public String toString() { return...
- Question #236
Given: 11. public void genNumbers() { 12. ArrayList numbers = new ArrayList(); 13. for (int i = 0; i < 10; i++) { 14. int value = i * ((int) Math.random()); 15. Integer intObj = ne...
- Question #237
Given a correctly compiled class whose source code is: 1. package com.sun.sjcp; 2. 3. public class Commander { 4. public static void main(String[] args) { 5. // more code here 6. }...
- Question #243
Given: interface DoStuff2 { float getRange(int low, int high); } interface DoMore { float getAvg(int a, int b, int c); } abstract class DoAbstract implements DoStuff2, DoMore { } c...
- Question #244
Given that Triangle implements Runnable, and: void go() throws Exception { Thread t = new Thread(new Triangle()); t.start(); for(int x = 1; x < 100000; x++) { //insert code here if...
- Question #246
Given: public class NamedCounter { private final String name; private int count; public NamedCounter(String name) { this.name = name; } public String getName() { return name; } pub...
- Question #248
Click the Exhibit button. What is the output if the main() method is run?
- Question #249
Given: class TestA { public void start() { System.out.println("TestA"); } } public class TestB extends TestA { public void start() { System.out.println("TestB"); } public static vo...
- Question #250
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?
- Question #251
Given: public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes...
- Question #252
Given: class Nav{ public enum Direction { NORTH, SOUTH, EAST, WEST } } public class Sprite{ // insert code here } Which code, inserted at line 14, allows the Sprite class to compil...
- Question #254
Given: public class A { public void doit() { } public String doit() { return "a"; } public double doit(int x) { return 1.0; } } What is the result?
- Question #256
Given: public class Rainbow { public enum MyColor { RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); private final int rgb; MyColor(int rgb) { this.rgb = rgb; } public int getRGB()...
- Question #258
Given: abstract class Vehicle { public int speed() { return 0; } class Car extends Vehicle { public int speed() { return 60; } class RaceCar extends Car { public int speed() { retu...
- Question #260
Given: public class SuperCalc { protected static int multiply(int a, int b) { return a * b;} } and: public class SubCalc extends SuperCalc{ public static int multiply(int a, int b)...
- Question #263
Given a method that must ensure that its parameter is not null: 11. public void someMethod(Object value) { 12. // check for null value ... 20. System.out.println(value.getClass());...
- Question #265
Given: public static Iterator reverse(List list) { Collections.reverse(list); return list.iterator(); } public static void main(String[] args) { List list = new ArrayList(); list.a...
- Question #267
Given: class X { public void foo() { System.out.print("X "); } } public class SubB extends X { public void foo() throws RuntimeException { super.foo(); if (true) throw new RuntimeE...
- Question #269
Given: public static Collection get() { Collection sorted = new LinkedList(); sorted.add("B"); sorted.add("C"); sorted.add("A"); return sorted; } public static void main(String[] a...
- Question #270
Given: public void testIfA() { if (testIfB("True")) { System.out.println("True"); } else { System.out.println("Not true"); } } public Boolean testIfB(String str) { return Boolean.v...
- Question #271
Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?
- Question #272
Click the Exhibit button. Given: public void method() { A a = new A(); a.method1(); } Which statement is true if a TestException is thrown on line 3 of class B?