1Z0-803 Exam Questions
266 real 1Z0-803 exam questions with expert-verified answers and explanations. Page 2 of 6.
- Question #51Using Loop Constructs
Given the code fragment: What is the result?
loop constructsfor loopwhile loopconditional statements - Question #52Java Basics
Given the following code: What will make this code compile and run?
compilation errorssyntax correctionstatic keywordaccess modifiers - Question #53Using Loop Constructs
Given: What is the result?
loopsarray accesscompilation errorsinfinite loop - Question #54Working with Methods and Encapsulation
You are writing a method that is declared not to return a value. Which two are permitted in the method body?
void methodsreturn statementmethod signature - Question #55Working with Selected Classes from the Java API
Identify two benefits of using ArrayList over array in software development.
ArrayListarraysCollections APIdynamic resizing - Question #56Using Operators and Decision Constructs
Which three are valid types for switch?
switch statementdata typescontrol flow - Question #57Using Operators and Decision Constructs
Give: What value should replace KK in line x to cause jj = 5 to be output?
conditional logicloopsoperatorsreverse engineering - Question #58Working with Selected Classes from the Java API
Given the following code fragment: What is the result if the integer value is 33?
String methodsconditional statementsstring manipulation - Question #59Creating and Using Arrays
Given the code fragment: Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}}; Systemout.printIn(array [4] [1]); System.out.printIn (array) [1][4]); int [] [...
multi-dimensional arraysarray indexingArrayIndexOutOfBoundsException - Question #60Using Loop Constructs
Given: How many times is 2 printed as a part of the output?
loop constructsnested loopsconditional statementstracing - Question #61Java Basics
Given: Which line causes a compilation error?
compilation errorsyntax error - Question #62Handling Exceptions
Given: What is the result?
NullPointerExceptionruntime errorexception handling - Question #63Handling Exceptions
Given: Which approach ensures that the class can be compiled and run?
try-catchchecked exceptionscompilation error - Question #64Using Operators and Decision Constructs
Given: What is the result?
code tracingprogram outputconditional statements - Question #65Working with Java Data Types
Which declaration initializes a boolean variable?
booleandata typesvariable declaration - Question #66Working with Methods and Encapsulation
Given: Why will the code not compile?
compilation errormethod definitionstatic methods - Question #67Working with Methods and Encapsulation
Given: This class is poorly encapsulated. You need to change the circle class to compute and return the area instead. What three modifications are necessary to ensure that the clas...
encapsulationaccess modifiersobject-oriented design - Question #68Using Operators and Decision Constructs
Given a code fragment: What is the result?
code tracingconditional statementsstring comparison - Question #69Handling Exceptions
Which two are possible outputs? public class Two { public static void main(String[] args) { try { doStuff(); system.out.println("1"); } catch { system.out.println("2"); }} public s...
try-catchRuntimeExceptionexception flowconditional execution - Question #70Using Loop Constructs
Given: public class MyFor { public static void main(String[] args) { for (int ii = 0; ii < 4; ii++) { System.out.println("ii = "+ ii); ii = ii +1; } } } What is the result?
for looploop iterationcode tracing - Question #71Creating and Using Arrays
Given the code fragment: int [][] array2d = new int[2][3]; System.out.println("Loading the data."); for ( int x = 0; x < array2d.length; x++) { for ( int y = 0; y < array2d[0].leng...
2D arraysarray indexingarray syntax - Question #72Using Loop Constructs
Given: public class DoBreak1 { public static void main(String[] args) { String[] table = {"aa", "bb", "cc", "dd"}; for (String ss: table) { if ( "bb".equals(ss)) { continue; } Syst...
enhanced for loopcontinue statementbreak statementcode tracing - Question #73Working with Methods and Encapsulation
Which three lines are illegal? 1. class StaticMethods { 2. static void one() { 3. two(); 4. StaticMethods.two(); 5. three(); 6. StaticMethods.four(); 7. } 8. static void two() { }...
static methodsinstance methodsmethod invocationcompilation error - Question #74Working with Inheritance
Which is a valid abstract class?
abstract classinheritanceclass declaration - Question #75Java Basics
View the exhibit: public class Student { public String name = ""; public int age = 0; public String major = "Undeclared"; public boolean fulltime = true; public void display() { Sy...
compilation errorobject fieldsclass members - Question #76Working with Selected Classes from the Java API
Given the code fragment: String name = "Spot"; int age = 4; String str ="My dog " + name + " is " + age; System.out.println(str); And StringBuilder sb = new StringBuilder(); Using...
StringBuilderstring concatenationJava API - Question #77Handling Exceptions
Given: public class Main { public static void main(String[] args) { try { doSomething(); } catch (SpecialException e) { System.out.println(e); }} static void doSomething() { int []...
exception propagationArrayIndexOutOfBoundsExceptiontry-catchcustom exceptions - Question #78Java Basics
View the exhibit: public class Student { public String name = ""; public int age = 0; public String major = "Undeclared"; public boolean fulltime = true; public void display() { Sy...
object instantiationnew keywordconstructors - Question #79Using Loop Constructs
What should keyword1 and keyword2 be respectively, in oreder to produce output 2345? int [] array = {1,2,3,4,5}; for (int i: array) { if ( i < 2) { keyword1 ; } System.out.println(...
enhanced for loopcontinue statementbreak statementloop control - Question #80Using 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 precedencearithmetic operatorscode tracing - Question #81Using 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);
logical operatorsrelational operatorsboolean expressions - Question #82Working with Selected Classes from the Java API
Which statement will emoty the contents of a StringBuilder variable named sb?
StringBuilderstring manipulationJava API methods - Question #83Java Basics
What is the result? Class StaticField { static int i = 7; public static void main(String[] args) { StaticFied obj = new StaticField(); obj.i++; StaticField.i++; obj.i++; System.out...
static membersclass variablesobject state - Question #84Creating and Using Arrays
Which two are valid array declaration?
array declarationarray syntax - Question #85Working 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 signaturecompilation errors - Question #86Java Basics
Given: public class MainMethod { void main() { System.out.println("one"); } static void main(String args) { System.out.println("two"); } public static void main(String[] args) { Sy...
main methodapplication entry pointmethod signature - Question #87Java Basics
Given: public class ScopeTest { int j, int k; public static void main(String[] args) { ew ScopeTest().doStuff(); } void doStuff() { nt x = 5; oStuff2(); System.out.println("x"); }...
variable scopeinstance variableslocal variablesfields - Question #88Working 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 invocationcompile-time errorsmethod parameters - Question #89Using 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[] arrar = {1,2,3}; for ( f...
for loopenhanced for looploop syntax - Question #90Working with Inheritance
Given: public class SampleClass { public static void main(String[] args) { AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new SampleClass(); sc = asc; System.o...
polymorphisminheritanceobject referencesgetClass() - Question #91Using Operators and Decision Constructs
Given the code fragment: int b = 3; if ( !(b > 3)) { System.out.println("square"); }{ System.out.println("circle"); } System.out.println("..."); What is the result?
if statementconditional logiccode blocks - Question #92Working 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 typemethod parameters - Question #93Handling Exceptions
Which two are Java Exception classes?
exception typesRuntimeExceptionIllegalArgumentException - Question #94Using Loop Constructs
Given the for loop construct: for ( expr1 ; expr2 ; expr3 ) { statement; } Which two statements are true?
for looploop controlloop syntax - Question #95Working with Selected Classes from the Java API
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 classstring manipulationreplace method - Question #96Creating and Using Arrays
Which two statements are true for a two-dimensional array?
two-dimensional arraysarray of arraysObject class methods - Question #97Working with Methods and Encapsulation
Which three statements are benefits of encapsulation?
encapsulationinformation hidingdata protectionmaintainability - Question #98Working with Selected Classes from the Java API
Given the code fragment: 1. ArrayList<Integer> list = new ArrayList<>(1); 2. list.add(1001); 3. list.add(1002); 4. System.out.println(list.get(list.size())); What is the result?
ArrayListIndexOutOfBoundsExceptionJava Collectionsruntime errors - Question #99Using Operators and Decision Constructs
Given the code fragment: Which code fragment prints blue, cyan, ?
control flowconditional statementsoutput prediction - Question #100Working with Methods and Encapsulation
View the Exhibit. 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...
object instantiationinstance methodssetter methods