1Z0-808 Exam Questions
100 real 1Z0-808 exam questions with expert-verified answers and explanations. Page 1 of 2.
- Question #1Working with Inheritance
Given: interface Readable { public void readBook(); public void setBookMark(); } abstract class Book implements Readable { // line n1 public void readBook() { } // line n2 } class...
interface implementationabstract classesinheritancemethod contracts - Question #2Working with Selected Classes from the Java API
Given: public static void main(String[] args) { List<String> names = new ArrayList<>(); names.add("Robb"); names.add("Bran"); names.add("Rick"); names.add("Bran"); if (names.remove...
ArrayList.remove()Method return valuesList operationsControl flow - Question #3Working with Inheritance
class A { public A(){ System.out.print ("A "); } } class B extends A{ public B(){ //line n1 System.out.print ("B "); } } class C extends B{ public C(){ //line n2 System.out.print (...
constructor chainingimplicit super()inheritance hierarchyconstructor execution order - Question #4Working with Methods and Encapsulation
class X { static int i; int j; public static void main(String[] args) { X x1 = new X(); X x2 = new X(); x1.i = 3; x1.j = 4; x2.i = 5; x2.j = 6; System.out.println( "x1.i = " + x1.i...
static variablesinstance variablesvariable scopeobject creation - Question #5Creating and Using Arrays
Given the code fragment: 1. public class Test { 2. public static void main(String[] args) { 3. /* insert code here */ 4. array[0]=10; 5. array[1]=20; 6. System.out.print (array[0]+...
array declarationarray initializationnew keywordsyntax - Question #6Using Loop Constructs
Given the code fragment: public class Test { public static void main(String[] args) { String[] arr = {"A", "B", "C", "D"}; for (int i = 0; i < arr.length; i++) { System.out.print (...
for loopscontinue/break statementscontrol flowloop execution - Question #7Java Basics
Given the code from the Greeting.java file: public class Greeting { public static void main(String[] args) { System.out.println("Hello " + args[0]); } } Which set of commands print...
command-line argumentsjavac compilationmain() methodargs parameter - Question #8Working with Methods and Encapsulation
Given: class Alpha { int ns; static int s; Alpha(int ns) { if (s < ns) { s = ns; this.ns = ns; } } void doPrint() { System.out.println("ns = " + ns + " s = " + s); } } And, public...
static variablesinstance variablesconstructorsdefault initialization - Question #9Working With Java Data Types
Given the code fragment: public class App { public static void main(String[] args) { String str1 = "Java"; String str2 = new String("Java"); //line n1 { System.out.println("Equal")...
String equalityequals() vs ==equalsIgnoreCase()object references - Question #10Working with Methods and Encapsulation
Given: public class SumTest { public static void doSum(Integer x, Integer y) { System.out.println("Integer sum is " + (x + y)); } public static void doSum(double x, double y) { Sys...
method overloadingtype matchingprimitive typesstring concatenation - Question #11Creating and Using Arrays
Given the code fragment: String[] strs = new String[2]; int idx = 0; for (String s : strs) { strs[idx].concat(" element " + idx); idx++; } for (idx = 0; idx < strs.length; idx++) {...
Array initialization with nullsNullPointerExceptionMethod calls on nullEnhanced for loop - Question #12Working with Inheritance
Given: class Vehicle { int x; Vehicle() { this(10); // line n1 } Vehicle(int x) { this.x = x; } } class Car extends Vehicle { int y; Car() { super(); this(20); // line n2 } Car(int...
constructorsconstructor chainingsuper() callsinheritance rules - Question #13Using Operators and Decision Constructs
Given the definitions of the MyString class and the Test class: MyString.java: package p1; class MyString { String msg; MyString(String msg) { this.msg = msg; } } Test.java: packag...
String concatenationtoString() methodStringBuilderObject.toString() - Question #14Working With Java Data Types
Given the code fragment: 3. public static void main(String[] args) { 4. int iVar = 100; 5. float fVar = 100.100f; 6. double dVar = 123; 7. iVar = fVar; 8. fVar = iVar; 9. dVar = fV...
Type ConversionsNarrowing ConversionsPrimitive TypesImplicit vs Explicit Casting - Question #15Working with Methods and Encapsulation
Given: MainTest.java: public class MainTest { public static void main(int[] args) { System.out.println("int main " + args[0]); } public static void main(Object[] args) { System.out...
Method overloadingmain methodJVM entry pointMethod resolution - Question #16Creating and Using Arrays
Given the code fragment: int num[][] = new int[1][3]; for (int i = 0; i < num.length; i++) { for (int j = 0; j < num[i].length; j++) { num[i][j] = 10; } } Which option represents t...
2D ArraysNested LoopsArray IndexingLoop Traversal - Question #17Working with Methods and Encapsulation
Given the code fragment: public class Person { String name; int age = 25; public Person(String name) { //line n1 this(); setName(name); } public Person(String name, int age) { //li...
constructor invocationthis() keywordconstructor chainingcompilation errors - Question #18Advanced Class Design
You are asked to develop a program for a shopping application, and you are given the following information: - The application must contain the classes Toy, EduToy, and ConsToy. - T...
abstract classabstract methodsclass hierarchyfinal methods - Question #19Creating and Using Arrays
int[] intArr = {15, 30, 45, 60, 75}; intArr[2] = intArr[4]; intArr[4] = 90; What are the values of each element in intArr after this code has executed?
array indexingarray assignmentvariable assignmentarray initialization - Question #20Using Loop Constructs
Given the following array: int[] intArr = {8, 16, 32, 64, 128}; Which two code fragments, independently, print each element in this array?
enhanced for looptraditional for looparray iterationloop semantics - Question #21Java Class Design
Given the content of three files: A.java: public class A { public void a () {} int a; } B.java: public class B { private int doStuff() { private int x = 100; return x++; } } C.java...
compilation rulespackage declarationaccess modifiersclass structure - Question #22Using Loop Constructs
Given the code fragment: int[] array = {1, 2, 3, 4, 5}; And given the requirements: 1. Process all the elements of the array in the order of entry. 2. Process all the elements of t...
enhanced for loopstandard for looparray iterationloop control - Question #23Working with Methods and Encapsulation
public class TestScope { public static void main (String[] args) { int var1 = 200; System.out.print (doCalc(var1)); System.out.print ("+var1); } static int doCalc (int var1) { var1...
variable scopemethod parameterspass-by-valuelocal variables - Question #24Working with Inheritance
Given the following class declarations: - public abstract class Animal - public interface Hunter - public class Cat extends Animal implements Hunter - public class Tiger extends Ca...
Generic CollectionsInheritanceType CompatibilityPolymorphism - Question #25Java Basics
Which statement is true about Java byte code?
Java bytecodeJREplatform independencecompilation - Question #26Java Basics
Given: ```java public class MarkList { int num; public static void graceMarks(MarkList obj4) { obj4.num += 10; } public static void main(String[] args) { MarkList obj1 = new MarkLi...
object instantiationreference variablesmemory allocation - Question #27Java Basics
Given: ```java public class Triangle { static double area; int b = 2, h = 3; public static void main(String[] args) { //line n1 double p, b, h; if (area == 0) { b = 3; h = 4; p = 0...
Variable ScopeDefinite AssignmentLocal VariablesCompilation Error - Question #28Using Operators and Decision Constructs
Given the code fragment: ```java public class Test { public static void main(String[] args) { //line n1 Switch (X) { case 1: System.out.println("One"); break; Case 2: System.out.pr...
switch statementsauto-boxing/unboxingtype compatibilityprimitive vs wrapper types - Question #29Working With Java Data Types
Given: ```java public class App { public static void main(String[] args) { Boolean[] bool = new Boolean[2]; bool[0] = new Boolean(Boolean.parseBoolean("true")); bool[1] = new Boole...
Boolean wrapper classnull handlingconstructor behaviortype conversion - Question #30Handling Exceptions
Given the following code for the classes MyException and Test: ```java public class MyException extends RuntimeException {} public class Test { public static void main(String[] arg...
exception inheritancecatch block matchingexception propagationRuntimeException hierarchy - Question #31Java Basics
public class App { String myStr = "7007"; public void doStuff(String str) { int myNum = 0; try { String myStr = str; myNum = Integer.parseInt(myStr); } catch (NumberFormatException...
Variable shadowingVariable scopetry-catch blocksScope resolution - Question #32Working with Inheritance
Which two are benefits of polymorphism?
PolymorphismInheritanceCode ReusabilityDynamic Dispatch - Question #33Creating and Using Arrays
int nums1[] = new int [3]; int nums2[] = {1, 2, 3, 4, 5}; nums1 = nums2; for (int x : nums1){ System.out.print (x + ":"); } What is the result?
array reference assignmentreference semanticsenhanced for looparray initialization - Question #34Java Basics
public class Product { int id; String name; public Product (int id, String name) { this.id = id; this.name = name; } } And given the code fragment: 4. Product p1 = new Product (101...
Reference Equalityequals() method== operatorObject Identity - Question #35Java Class Design
Given the following classes: public class Employee { public int salary; } public class Manager extends Employee { public int budget; } public class Director extends Manager { publi...
inheritancefield accessclass hierarchycompilation errors - Question #36Java Class Design
class Product { double price; } public class Test { public static void updatePrice (Product product, double price) { product.price = price; price = 2; product.price = product.price...
pass by valueobject referencesprimitive typesmethod parameters - Question #37Using Operators and Decision Constructs
if (@Var++ < 10) { System.out.println (@Var + " Hello World!"); } else { System.out.println (@Var + " Hello Universe!"); } What is the result if the integer aVar is 9?
Post-increment operatorsBoolean expressionsConditional statementsOperator evaluation - Question #38Localization
public static void main(String[] args) { String date = "2014-05-04"; .parse("2014-05-04T00:00:00.000"); .format(DateTimeFormatter.ISO_DATE_TIME); System.out.println(date); } What i...
DateTimeFormatterdate parsingLocalDateTimeJava date API - Question #39Working With Java Data Types
public static void main(String[] args) { Short s1 = 200; Integer s2 = 400; long s3 = (long) (s1 + s2); //line n1 String s4 = (String) (s3 * s2); //line n2 System.out.println("Sum i...
Auto-boxing/unboxingType castingType promotionString conversion - Question #40Working with Methods and Encapsulation
What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?
encapsulationaccess modifiersdata hidingOOP principles - Question #41Working with Inheritance
Given the code fragment: ```java abstract class Planet { protected void revolve() { //line n1 } } abstract void rotate(); class Earth extends Planet { void revolve() { //line n3 }...
access modifiersmethod overridingabstract methodsinheritance - Question #42Working with Inheritance
Given: ```java class Vehicle { String type = "4W"; int maxSpeed = 100; Vehicle(String type, int maxSpeed) { this.type = type; this.maxSpeed = maxSpeed; } } class Car extends Vehicl...
Implicit super()Constructor chainingInheritanceNo-arg constructor - Question #43Handling Exceptions
Given the code fragment: ```java 1. class X { 2. public void printFileContent () { 3. /* code goes here */ 4. throw new IOException(); 5. } 6. } 7. public class Test { 8. public st...
Checked Exceptionsthrows DeclarationException PropagationMethod Signatures - Question #44Working with Methods and Encapsulation
Given the following two classes: ```java public class Customer { ElectricAccount acct = new ElectricAccount(); public void useElectricity(double kWh) { acct.addKwh(kWh); } } public...
encapsulationaccess modifiersclass invariantsdata protection - Question #45Working with Methods and Encapsulation
Person.java: public class Person { String name; int age; public Person(String n, int a) { name = n; age = a; } public String getName() { return name; } public int getAge() { return...
Lambda expressionsPredicate interfaceFunctional interfacesType inference - Question #46Using Loop Constructs
public static void main(String[] args) { String[][] arr = {{"A", "B", "C"}, {"D", "E"}}; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { System.out...
nested loopsbreak statement2D arrayscontinue statement - Question #47Working with Selected Classes from the Java API
QUESTION 58 Given the code fragment: public static void main(String[] args) { String str = " "; str.trim(); System.out.println(str.equals("") + " " + str.isEmpty()); } What is the...
String immutabilitytrim() methodequals() methodisEmpty() method - Question #48Working with Inheritance
class CD { int r; CD(int r) { this.r=r; } } class DVD extends CD { int c; DVD(int r, int c) { // line n1 } } And given the code fragment: DVD dvd = new DVD(10, 20); Which code frag...
constructor chainingsuper keywordinheritancesubclass initialization - Question #49Using Loop Constructs
QUESTION 60 Given the code fragment: int a[] = {1, 2, 3, 4, 5}; for (XXXX) { System.out.print (a[e]); } Which option can replace xxxx to enable the code to print 135?
for loop syntaxarray indexingiteration controlloop increment - Question #50Working with Methods and Encapsulation
QUESTION 61 Which statement best describes encapsulation?
encapsulationaccess controldata hidingOOP principles