1Z0-808 Exam Questions
99 real 1Z0-808 exam questions with expert-verified answers and explanations. Page 2 of 2.
- Question #51Java Basics
QUESTION 62 Given the code fragment from three files: SalesMan.java: package sales; public class SalesMan { } Product.java: package sales.products; public class Product { } Market....
package structureimport statementsclass resolutionpackage hierarchy - Question #52Using Loop Constructs
Given the code fragment: String shirts[][] = new String[2][2]; shirts[0][0] = "red"; shirts[0][1] = "blue"; shirts[1][0] = "small"; shirts[1][1] = "medium"; Which code fragment pri...
2D arraysnested loopsloop controlarray indexing - Question #53Working with Selected Classes from the Java API
Given the code fragment: public static void main(String[] args) { StringBuilder sb = new StringBuilder(5); String s = ""; if (sb.equals(s)) { System.out.println("Match 1"); } else...
StringBuilder vs String equalityequals() method behaviortoString() conversionObject comparison - Question #54Working with Methods and Encapsulation
package p1; public class Acc { int p; private int q; protected int r; public int s; } Test.java: package p2; import p1.Acc; public class Test extends Acc { public static void main(...
Access ModifiersEncapsulationPackage-privateInheritance - Question #55Handling Exceptions
Given the code fragment: public static void main(String[] args) { ArrayList myList = new ArrayList(); String[] myArray; try { while (true) { myList.add("My String"); } } Catch (Run...
exception hierarchyuncaught errorsOutOfMemoryErrortry-catch blocks - Question #56Using Operators and Decision Constructs
Given: System.out.println("5 + 2 = " + 3 + 4); System.out.println("5 + 2 = " + (3 + 4)); What is the result?
string concatenationoperator precedencetype coercionleft-to-right evaluation - Question #57Working With Java Data Types
Given: public static void main(String[] args) { String ta = "A"; ta = ta.concat("B"); String tb = "C"; ta = ta.concat(tb); ta.replace('C', 'D'); System.out.println(tb); System.out....
String immutabilityString.concat()String.replace()variable references - Question #58Using Loop Constructs
Given the code fragment: 3. public static void main(String[] args) { 4. int x = 5; 5. while (isAvailable(x)) { 6. System.out.print(x); 7. } 8. } 9. 10. public static boolean isAvai...
Post-decrement operatorMethod parametersWhile loopLoop termination - Question #59Using Operators and Decision Constructs
Given the code fragment: 4. public static void main(String[] args) { 5. boolean opt = true; 6. switch (opt) { 7. case true: 8. System.out.print("True"); 9. break; 10. default: 11....
switch statementsboolean typetype matchingcase comparison - Question #60Using Loop Constructs
Given the following main method: public static void main(String[] args) { int num = 5; do { System.out.print(num-- + " "); } while (num == 0); } What is the result?
do-while loopspost-decrement operatorloop condition evaluationcontrol flow - Question #61Using Operators and Decision Constructs
Given the code fragment: int x = 100; int a = x++; int b = ++x; int c = x++; int d = (a < b) ? (a < c) ? a : (b < c) ? b : c; System.out.println(d); What is the result?
Ternary operatorOperator syntaxPre/Post-incrementParsing - Question #62Creating and Using Arrays
Given: public class Test { public static void main(String[] args) { String[][] chs = new String[2][]; chs[0] = new String[2]; chs[1] = new String[5]; int i = 97; for (int a = 0; a...
jagged arraysnested loopsarray initializationnull references - Question #63Java Basics
Given the exhibit: public class Student { public String name = ""; public int age = 0; public String major = "Undeclared"; public boolean fulltime = true; public void display() { S...
object instantiationnew keywordconstructorclass declaration - Question #64Using Loop Constructs
What should keyword1 and keyword2 be respectively, in order to produce output 2345? int [] array = {1,2,3,4,5}; for (int i: array) { if (i < 2) { keyword1 ; } System.out.println(i)...
continue keywordbreak keywordloop control flowfor-each loops - Question #65Using Operators and Decision Constructs
What is the result? int i, j=0; i = (3 * 2 +4 +5) ; j = (3 * ((2+4) + 5)); System.out.println("i:" + i + "\nj:" +j);
operator precedenceorder of operationsarithmetic evaluationparentheses - Question #66Using Operators and Decision Constructs
What is the result? boolean log3 = ( 5.0 != 6.0) && ( 4 != 5); boolean log4 = (4 != 4) || (4 == 4); System.out.println("log3:" + log3 + "\nlog4:" + log4);
boolean operatorscomparison operatorslogical AND/ORboolean expressions - Question #67Working With Java Data Types
Which statement will empty the contents of a StringBuilder variable named sb?
StringBuilderString manipulationdelete() methodJava API - Question #68Java Basics
What is the result? class StaticField { static int i = 7; public static void main(String[] args) { StaticField obj = new StaticField(); obj.i++; StaticField.i++; obj.i++; System.ou...
Static fieldsClass variablesVariable scopePost-increment operator - Question #69Working with Methods and Encapsulation
Given: class Overloading { int x(double d) { System.out.println("one"); return 0; } String x(double d) { System.out.println("two"); return null; } double x(double d) { System.out.p...
method overloadingmethod signaturereturn type rulescompilation error - Question #70Working with Methods and Encapsulation
public static void main(String[] args) { System.out.println("three"); } void mina(Object[] args) { System.out.println("four"); } What is printed out when the program is executed?
main method entry pointmethod invocationmethod signaturesprogram execution - Question #71Java Basics
Given: public class ScopeTest { int j, int k; public static void main(String[] args) { ew ScopeTest().doStuff(); } void doStuff() { int x = 5; doStuff2(); System.out.println("x");...
variable scopefieldsinstance variableslocal variables - Question #72Working with Methods and Encapsulation
A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the results?
method invocationmethod signaturesargument matchingcompile-time errors - Question #73Using Loop Constructs
Which three are valid replacements for foo so that the program will compiled and run? public class ForTest { public static void main(String[] args) { int[] array = {1,2,3}; for ( f...
for loopsenhanced for syntaxloop initializationfor-each - Question #74Working with Inheritance
Given: public class SampleClass { public static void main(String[] args) { AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new SampleClass(); sc = asc; System.o...
polymorphismobject referencesgetClass() methodinheritance - Question #75Using Operators and Decision Constructs
Given the code fragment: int b = 3; if ( (b > 3) ) { System.out.println("square"); } else { System.out.println("circle"); } System.out.println("..."); What is the result?
if-else statementsboolean expressionsconditional logiccontrol flow - Question #76Working with Methods and Encapsulation
What is the proper way to defined a method that take two int values and returns their sum as an int value?
method declarationreturn typesmethod parametersmethod syntax - Question #77Handling Exceptions
Which two are Java Exception classes?
exception classesJava API exceptionsstandard libraryclass identification - Question #78Using Loop Constructs
Given the for loop construct: for ( expr1 ; expr2 ; expr3 ) { statement; } Which two statements are true?
for loop syntaxloop initializationloop conditionenhanced for loop - Question #79Working With Java Data Types
What is the result? public class StringReplace { public static void main(String[] args) { String message = "Hi everyone!"; System.out.println("message = " + message.replace("e", "X...
String.replace()String methodsString manipulationmethod behavior - Question #80Creating and Using Arrays
Which two statements are true for a two-dimensional array?
2D arraysArray implementationObject inheritance - Question #81Working with Methods and Encapsulation
Which three statements are benefits of encapsulation?
EncapsulationData HidingClass DesignInvariant Protection - Question #82Working with Selected Classes from the Java API
Given the code fragment: 1. ArrayList<Integer> list = new ArrayList<>(); 2. list.add(1001); 3. list.add(1002); 4. System.out.println(list.get(list.size())); What is the result?
ArrayList indexingbounds checkingsize() methodIndexOutOfBoundsException - Question #84Working with Methods and Encapsulation
public class Hat { public int ID =0; public String name = "hat"; public String size = "One Size Fit All"; public String color=""; public String getName() { return name; } public vo...
method invocationinstance methodsobject method callsencapsulation - Question #85Working With Java Data Types
Which code fragment cause a compilation error?
type conversionfloat/double typesnarrowing conversioncompilation errors - Question #86Working with Methods and Encapsulation
Given: class X { static void m (int[] i) { i[0] += 7; } public static void main (String[] args) { int[] j = new int[1]; j[0] = 12; m(j); System.out.println(j[0]); } } What is the r...
array-parameterspass-by-valuemethod-callsreference-types - Question #87Working with Inheritance
Given: 1. public class SampleClass { 2. public static void main (String[] args) { 3. AnotherSampleClass asc = new AnotherSampleClass(); 4. SampleClass sc = new SampleClass(); 5. //...
InheritanceType compatibilityReference assignmentUpcasting - Question #88Handling Exceptions
Given: public class MarksOutOfBoundsException extends IndexOutOfBoundsException { } public class GradingProcess { void verify(int marks) throws IndexOutOfBoundsException { if (mark...
exception inheritancetry-catch blocksruntime typecustom exceptions - Question #89Working with Inheritance
Given: 1. interface Pet { } 2. class Dog implements Pet { } 3. class Beagle extends Dog { } Which three are valid?
InheritancePolymorphismInterface ImplementationType Compatibility - Question #90Working with Selected Classes from the Java API
Given the code fragment: StringBuilder sb = new StringBuilder(); sb.append("World"); Which fragment prints Hello World?
StringBuilder.insert()StringBuilder APIString manipulationmethod signatures - Question #91Working with Inheritance
Given: package pkg1; class Bb {} public class Ee { private Ee () {} } package pkg2; final class Ww; package pkg3; public abstract class Dd { void m() { } } And, 1. package pkg4; 2....
Access ModifiersClass InheritanceFinal ClassesAbstract Classes - Question #92Working With Java Data Types
Change line 5 to:
variable declarationdata typestype compatibilityprimitives - Question #93
Given the code fragment: Which statement is true? ```java Class Student { String name; int age; } And, 1. public class Test { 2. public static void main(String[] args) { 3. Student...
- Question #94Creating and Using Arrays
Given: ```java public class Test { public static void main(String[] args) { char[] arr = {97, 't', 'e', '\n', 'i', '\t', 'o'}; for (char var: arr) { System.out.print(var); } System...
char arraysASCII encodingescape sequencesenhanced for loop - Question #95Working with Inheritance
Given the class definitions: ```java class Shape { } class Square extends Shape { } ``` Given the variable declarations: ```java Shape shape1 = null; Square square1 = null; ``` Whi...
type castinginheritanceupcastingdowncasting - Question #96
Given the code fragments: ```java 9. class Student { 10. int rollnumber; 11. String name; 12. List<String> courses = new ArrayList<>(); 13. // insert code fragment here 14. public...
- Question #97Using Loop Constructs
Given: ```java public class Test2 { public static void main(String[] args) { int ar1[] = {2, 4, 6, 8}; int ar2[] = {1, 3, 5, 7, 9}; int ar3[] = ar1; for (int e2 : ar2) { System.out...
Array referenceEnhanced for loopLoop iterationCode flow - Question #98Working with Methods and Encapsulation
Given: ```java public class Test2 { public static void doChange(int[] arr) { for (int pos = 0; pos < arr.length; pos++){ arr[pos] = arr[pos] + 1; } } public static void main(String...
method signaturesarray vs primitive typesparameter matchingcompilation errors - Question #99Creating and Using Arrays
Which two are valid declarations of a two-dimensional array?
2D arraysArray syntaxMultidimensional arraysDeclarations - Question #100Using Operators and Decision Constructs
Given the following Java code: public class CheckIt { public static void main (String[] args) { if (doCheck()) { System.out.print("square "); } System.out.print("..."); } public st...
type_mismatchif_statementboolean_expressiontype_compatibility