1Z0-811 Exam Questions
73 real 1Z0-811 exam questions with expert-verified answers and explanations. Page 1 of 2.
- Question #1Data Types and Operators
Which statement is true about primitive variables?
primitive typescomparison operatorsequals methodreference vs primitive - Question #2Control Flow
Given the code fragment: boolean checkOut = true; int days = 0; while (checkOut) { days++; if (days > 3) { checkOut = false; } } System.out.print (days); What is the result?
while looploop terminationconditional statementscontrol flow - Question #3Java Basics
Identify two Java reserved words.
reserved wordskeywordssyntax basicslanguage fundamentals - Question #4Java Basics
Which statement is true about a Java method?
method declarationmethod scopesyntax constraintsnested methods - Question #5Object-Oriented Programming Principles
Given: class Messenger { String msg; Messenger(String msg) {this.msg = msg;} public void writeMsg() { System.out.println(msg); } public void readMsg () { // line n1 } } Messenger m...
method invocationinstance methodsscope resolutionthis reference - Question #6Java Basics
Given the code fragment: 1. class App { 2. 3. } Which two code fragments are valid at line 2?
Java file structureCode placement rulesPackage/import declarationsClass members - Question #7Control Flow
You have been asked to develop a Java program that prints the elements of an array in reverse order. Which looping statement cannot be used to meet the requirement?
Loop ConstructsArray IterationEdge CasesControl Flow - Question #8Java Basics
Given the code fragment: //line n1 public class App { public static void main(String[] args) { List<Double> nums = new ArrayList<>(); nums.add(Math.PI); nums.add(new Random().nextD...
importsjava.langjava.utilpackage visibility - Question #9Arrays and Logic
Given the code fragment: List<String> items = new ArrayList<> (); items.add(1, "pen"); items.add(2, "pencil"); items.add(3, "erasers"); items.add("paper"); for (String x : items) {...
ArrayListIndexOutOfBoundsExceptionMethod overloadingCollection API - Question #10Object-Oriented Programming Principles
Given the code fragment: class Course { String name; static int count = 0; Course(String name) { this.name = name; count++; } } public class App { public static void main(String[]...
static variablesinstance variablesmember accessclass vs instance scope - Question #11Java Basics
Given: public class Student { string sName; char grade; public static void main (String[] args) { Student s = new Student (); System.out.println ("\"" + s.sName + ":" + s.grade + "...
default valuesinstance variableschar typestring concatenation - Question #12Object-Oriented Programming Principles
Which two Java reserved words are used to implement encapsulation?
encapsulationaccess modifierspublic/private keywordsdata hiding - Question #13Object-Oriented Programming Principles
Given the code fragment: class Ball { double weight; } public class App { public static void main (String[] args) { //line n1 } } Which code fragment can be inserted at line n1 to...
object instantiationinstance variablesdefault valuesconstructors - Question #14Java Basics
Which two statements are true about the Java Runtime Environment (JRE)?
JREBytecode InterpretationGarbage CollectionJVM - Question #15Java Basics
Identify two features of Java.
Platform IndependenceJava FeaturesJVMWORA - Question #16Object-Oriented Programming Principles
Given public class App { int num; public int add(int x) { num = num + x; return num; } public void add(int x) { num = num + x; } public static void main (String[] args) { App obj =...
Method OverloadingMethod SignatureReturn Type RulesCompilation Error - Question #17Arrays and Logic
Given the code fragment: List<String> names = new ArrayList<>(); names.add("Julia"); names.add("Peter"); for (Iterator<String> itr = names.iterator(); itr.hasNext();) { System.out....
IteratorArrayListCollections APIIteration Order - Question #18Arrays and Logic
Given the code fragment: // line n1 num = new int[10]; Which code fragment can be inserted at line n1 to enable the code to compile?
Array declarationVariable declaration syntaxType systemData types - Question #19Data Types and Operators
Given the code fragment: String s = "Hello Java"; System.out.println (s.length()); s.concat ("SE 8"); System.out.println (s.length ()); What is the result?
String immutabilityString concatenationString.length()String methods - Question #20Exception Handling and Methods
Given the code fragment: public static void main (String[] args) { int[] arr = {10, 0}; int i = 0; try { int answer = arr[i] / arr[i + 1]; } catch (Exception e) { System.out.printl...
exception handlingcatch block orderingexception hierarchycompilation error - Question #21Control Flow
Given the code fragment: String[] codes = {"CA", "JP", "US", "CA", "UK"}; int count = 0; for (String c : codes) { if (c.equals("CA")) { continue; } else { count++; } } System.out.p...
continue statementloop control flowString.equals()counter logic - Question #22Arrays and Logic
Given the code fragment: String flavors[] = {"Vanilla", "Chocolate"}; int choice = 2; switch (choice) { case 1: System.out.println("Selected " + flavors[1] + " flavor."); break; ca...
Array indexingArray bounds violationSwitch statementsRuntime exceptions - Question #23Object-Oriented Programming Principles
Given: public class Test { static int var2 = 200; public static void print () { System.out.println (var2); } public void print(int var1) { System.out.println(var1); var2 = var2 + v...
Method OverloadingStatic vs Instance MethodsMethod ResolutionStatic Context Access - Question #24Object-Oriented Programming Principles
Given: class Product { String color = null; Product (Product p) { this.color = p.color; } } And the code fragment: Product p1 = new Product (); // line n1 p1.color = "White"; Produ...
ConstructorsObject initializationField default valuesCopy constructor - Question #25Object-Oriented Programming Principles
Given the code: public class Calc { // line n1 return a + b; } public static void main (String[] args) { Calc obj = new Calc(); int c = obj.sum(10, 20); System.out.println("sum is...
method signatureparameter declarationsyntax rulesmethod calls - Question #26Java Basics
You have a microprocessor board, such as Raspberry PI, wired to control a drone. Which edition of Java is geared towards use of simple, closed systems with constrained memory requi...
Java SE Embeddedembedded systemsJava editionsconstrained memory - Question #27Data Types and Operators
Given the code fragment: // line n1 switch (var) { case "1": System.out.println ("one"); break; } Which code fragment, when inserted at line n1, enables the code to print one?
switch statementString literalstype matchingprimitive vs reference types - Question #28
Which statement is true about a mutator method?
- Question #29Data Types and Operators
Given the code fragment: int a = 10; int b = 20; int c = 30; System.out.println (a++ > 10 || ++b <= 21); System.out.println (a > 10 && ++b <= 22); System.out.println (a <= 11 && b...
post/pre-increment operatorslogical operator short-circuitoperator precedencevariable state tracking - Question #30
Identify two valid data types for the operands of the addition (+) operator?
- Question #31Data Types and Operators
Given the code fragment: String s1 = "foo-bar"; String s2 = new String ("foo-bar"); System.out.print (s1.equals(s2) + " "); System.out.print (s1 == s2); System.out.print (" " + s1....
String equality== vs .equals()String methodsReference comparison - Question #32
Given the code fragment: 1. String name = "Fred"; 2. System.out.println("Hello" + // Saying hello 3. name); // to Fred 4. System.out.println("Good /* and " + 5. "*/ greeting */ day...
- Question #33
Which statement is valid?
- Question #34Java Basics
Given these class definitions: class MyClassA { } public class MyClassB { } class MyClassC extends Object { } class MyClassD { public static void main (String [] args) { } } Which...
access modifiersclass declarationspublic/default accessfile structure - Question #35Data Types and Operators
Given: public class Course { public static void main (String [] args) { double courseFee = 1000.0; float percentage = 5.0f; // line n1 newFee = courseFee * percentage; System.out.p...
Type PromotionArithmetic OperationsType CompatibilityPrimitive Types - Question #36Object-Oriented Programming Principles
Given: class Bus { String type = "default"; // line n1 Bus (String type) { // line n2 this.type = type; } } public class App{ public static void main(String[] args) { Bus b1 = new...
constructorsdefault constructorconstructor overloadingobject instantiation - Question #37Java Basics
Given: 1. class Test { 2. /* comment text 1 */ 3. // comment text 2 // 4. /* comment text 3 5. and comment text 4 // 6. /* comment text 5 7. and comment text 6 */ 8. } At which lin...
Java CommentsComment SyntaxCompilation ErrorsBlock Comments - Question #38Data Types and Operators
Given: public static void main (String[] args) { boolean value1 = 10 + 5 >= 2 + 13; int value2 = 0; if (value1 == true) { value2 = 5 * 3 + 10 / 2; } else { value2 = 5 / 3 + 10 * 2;...
operator precedencecomparison operatorsarithmetic evaluationconditionals - Question #39Data Types and Operators
Given the code fragment: String digits = "0123456789"; System.out.println( digits.substring( digits.indexOf("4"), digits.indexOf("8"))).concat("89")); What is the result?
String.substring()String.indexOf()String.concat()method chaining - Question #40Arrays and Logic
Given the code fragment: int[] num = new int[2]; num[0] = 10; num[1] = 15; List<Integer> lst = new ArrayList<>(2); lst.add(10); lst.add(15); num[1] = 20; lst.add(20); for (int x: n...
arraysArrayListenhanced-for-loopstype-compatibility - Question #41Exception Handling and Methods
Which statement is true about exception handling?
exception handlingtry-catch blocksexception hierarchycatch block ordering - Question #42Data Types and Operators
Given the code fragment: System.out.println(10 == 10 && ! (5 != 5)); System.out.println(10 < 8 | | 10 > 2); What is the result?
boolean operatorscomparison operatorslogical expressionsoperator precedence - Question #43Data Types and Operators
Given the code fragment: int value = 10; int a = ++value; int b = value; int c = value++; if (a <= b && a <= c) { if (b <= c) { a = ++b; } else { a = ++c; } } System.out.println(a)...
pre-increment vs post-incrementoperator semanticsvariable assignmentcontrol flow - Question #44Data Types and Operators
Given the code fragment: String inputFromConsole = " betaTEST "; String cleanedInput; cleanedInput = inputFromConsole.toUpperCase(); cleanedInput = cleanedInput.trim(); System.out....
String methodsString manipulationtoUpperCasetrim - Question #45Control Flow
Given the code int num = 100; int count = 0; do { num--; count++; } while (count > 1); System.out.println ("num = " + num); What is the result?
do-while loopsloop terminationcondition evaluationcontrol flow - Question #46Java Basics
Which method identifier is correct according to Java naming conventions?
Method namingCamelCaseIdentifiersJava conventions - Question #47
Given the code of Student.java: class Course { String courseName; } public class Student { String stuName; public static void main(String[] args) { Student s = new Student(); s.stu...
- Question #48Data Types and Operators
Given the code fragment: 5. float fValue = 120; 6. int iValue = fValue; 7. double dValue = fValue; 8. long lValue = fValue; At which line does a compilation error occur?
type castingimplicit conversionprimitive typeswidening/narrowing - Question #49Arrays and Logic
Given the code fragment: int[] arr = {1, 2, 3, 4, 5}; Which for loop statement can be used to print 135?
for loopsarray indexingstep increment - Question #50Data Types and Operators
Given the code fragment: String a = "Java"; String b = new String("Java"); System.out.println(a.equals(b)); System.out.println(a==b); What is the result?
String equalityequals() vs ==reference vs valueString interning