1Z0-851 Exam Questions
190 real 1Z0-851 exam questions with expert-verified answers and explanations. Page 3 of 4.
- Question #114
Given: 11. class X { public void foo() { System.out.print("X "); } } 12. 13. public class SubB extends X { 14. public void foo() throws RuntimeException { 15. super.foo(); 16. if (...
- Question #120
A company has a business application that provides its users with many different reports: receivables reports, payables reports, revenue projects, and so on. The company has just p...
- Question #124
Given: class Employee { String name; double baseSalary; Employee(String name, double baseSalary) { this.name = name; this.baseSalary = baseSalary; } } 09. public class SalesPerson...
- Question #125
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing...
- Question #127
Given: 05. class Building { } 06. public class Barn extends Building { 07. public static void main(String[] args) { 08. Building build1 = new Building(); 09. Barn barn1 = new Barn(...
- Question #128
Given: public class TestOne { public static void main (String[] args) throws Exception { Thread.sleep(3000); System.out.println("sleep"); } } What is the result?
- Question #130
Which two statements are true? (Choose two.)
- Question #132
Given classes defined in two different files: package util; public class BitUtils { public static void process(byte[] b) { /* more code here */ } } 1. package app; 2. 3. public cla...
- Question #134
Given: class Snoochy { Boochy booch; public Snoochy() { booch = new Boochy(this); } } class Boochy { Snoochy snooch; public Boochy(Snoochy s) { snooch = s; } } And the statements:...
- Question #135
Given: public class Batman { int squares = 81; public static void main(String[] args) { new Batman().go(); } void go() { incr(++squares); System.out.println(squares); } void incr(i...
- Question #138
Click the Exhibit button. What is the output of the program shown in the exhibit?
- Question #139
Given the following directory structure: bigProject |--source | |--Utils.java | |--classes |-- And the following command line invocation: javac -d classes source/Utils.java Assume...
- Question #140
Given: interface Fish { } class Perch implements Fish { } class Walleye extends Perch { } class Bluegill { } public class Fisherman { public static void main(String[] args) { Fish...
- Question #142
Given: 11. public void testIfA() { 12. if (testIfB("True")) { 13. System.out.println("True"); 14. } else { 15. System.out.println("Not true"); 16. } 17. } 18. public Boolean testIf...
- Question #144
Given: 31. //some code here line 31 32. try { 33. //some code here line 33 34. } catch (NullPointerException e1) { 35. //some code here line 35 36. } finally { 37. //some code here...
- Question #147
Given: 10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args ) { 15. Beta...
- Question #148
Given: 33. try { 34. //some code here 35. } catch (NullPointerException e1) { 36. System.out.print("a"); 37. } catch (Exception e2) { 38. System.out.print("b"); 39. } finally { 40....
- Question #149
Given: 1. public class Test { 2. public enum Dogs {collie, harrier, shepherd}; 3. public static void main(String [] args) { 4. Dogs myDog = Dogs.shepherd; 5. switch (myDog) { 6. ca...
- Question #151
Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?
- Question #153
Given: 09. class Line { 10. public static class Point {} 11. } 12. 13. class Triangle { 14. public Triangle(){ 15. // insert code here 16. } 17. } Which code, inserted at line 15,...
- Question #154
Given: 10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows th...
- Question #155
Given: interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?
- Question #156
Given: 11. public class Rainbow { 12. public enum MyColor { 13. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); 14. private final int rgb; 15. MyColor(int rgb) { this.rgb = rgb; }...
- Question #157
Given: 3. import java.util.*; 4. public class G1 { 5. public void takeList(List<? extends String> list) { 6. // insert code here 7. } 8. } Which three code fragments, inserted inde...
- Question #158
Given: 09. class One { 10. void foo() { } 11. } 12. 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly...
- Question #159
Given: public interface A { public void m1(); } class B implements A { } class C implements A { public void m1() { } } class D implements A { public void m1(int x) { } } abstract c...
- Question #161
Click the Exhibit button. What is the result?
- Question #162
Given: NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4); nf.setMinimumFractionDigits(2); String a = nf.format(3.1415926); String b = nf.format(2); Which...
- Question #163
Given: 11. String test = "a1b2c3"; 12. String[] tokens = test.split("\\d"); 13. for(String s: tokens) System.out.print(s + " "); What is the result?
- Question #164
Given: public class Person { private String name, comment; private int age; public Person(String n, int a, String c) { name = n; age = a; comment = c; } public boolean equals(Objec...
- Question #166
Given: String csv = "Sue,5,true,3"; Scanner scanner = new Scanner( csv ); scanner.useDelimiter(","); int age = scanner.nextInt(); What is the result?
- Question #167
Given: import java.util.*; public class WrappedString { private String s; public WrappedString(String s) { this.s = s; } public static void main(String[] args) { HashSet<Object> hs...
- Question #168
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true? (Choose two.)
- Question #169
Given: 01. import java.util.*; 02. public class Example { 03. public static void main(String[] args) { 04. // insert code here 05. set.add(new Integer(2)); 06. set.add(new Integer(...
- Question #177
Given: 01. class TestException extends Exception { } 02. class A { 03. public String sayHello(String name) throws TestException { 04. if(name == null) throw new TestException(); 05...
- Question #179
Given: public class Breaker { static String o = ""; public static void main(String[] args) { z: o = o + 2; for(int x = 3; x < 8; x++) { if(x==4) break; if(x==6) break z; o = o + x;...
- Question #180
Given: 05. class A { 06. void foo() throws Exception { throw new Exception(); } 07. } 08. class SubB2 extends A { 09. void foo() { System.out.println("B "); } 10. } 11. class Teste...
- Question #182
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. } Which co...
- Question #184
Given: public class Boxer1{ Integer i; int x; public Boxer1(int y) { x = i+y; System.out.println(x); } public static void main(String[] args) { new Boxer1(new Integer(4)); } } What...
- Question #187
Given: 11. public static void main(String[] args) { 12. Integer i = new Integer(1) + new Integer(2); 13. switch(i) { 14. case 3: System.out.println("three"); break; 15. default: Sy...
- Question #188
Given: class Money { private String country = "Canada"; public String getC() { return country; } } class Yen extends Money { public String getC() { return super.country; } } public...
- Question #190
Which three statements are true? (Choose three.)
- Question #191
Given: package test; class Target { public String name = "hello"; } What can directly access and change the value of the variable name?
- Question #193
Click the Exhibit button. What two must the programmer do to correct the compilation errors? (Choose two.) 1. public class Car { 2. private int wheelCount; 3. private String vin; 4...
- Question #194
A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access...
- Question #195
Given: class Thingy { Meter m = new Meter(); } class Component { void go() { System.out.print("c"); } } class Meter extends Component { void go() { System.out.print("m"); } } class...
- Question #196
Given: 10. interface Jumper { public void jump(); } ... 20. class Animal {} ... class Dog extends Animal { Tail tail; 32. } ... class Beagle extends Dog implements Jumper{ public v...
- Question #197
Click the Exhibit button. What is the result?
- Question #198
Given a valid DateFormat object named df, and 16. Date d = new Date(0L); 17. String ds = "December 15, 2004"; 18. //insert code here What updates d's value with the date represente...
- Question #199
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)