Java Certification (1Z0-815) Exam Simulation [2020] Set 1


Consider below code fragment:



Which of the following options replaces /*INSERT*/ such that there is no compilation error?


Options are :

Answer :abstract List get() throws ArrayIndexOutOfBoundsException;

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 31


Given below the directory/file structure on Windows platform:


Below are the file contents:-


C:\src\library\com\udayankhattry\books\Book.java:


C:\src\library\com\udayankhattry\members\Member.java:


C:\src\library\module-info.java:


The author of this module wants to export the package 'com.udayankhattry.books' to 'bookhouse' and 'onlinestore' modules only and the package 'com.udayankhattry.members' to 'test' module only.


Which of the following options, when inserted in module-info.java file, will fulfill his requirements?


Options are :

  • exports com.udayankhattry.books to bookhouse, onlinestore; exports com.udayankhattry.members to test; (Correct)
  • export com.udayankhattry.books to bookhouse; export com.udayankhattry.books to onlinestore; export com.udayankhattry.members to test;
  • exports com.udayankhattry.books to bookhouse; exports com.udayankhattry.books to onlinestore; exports com.udayankhattry.members to test;
  • export com.udayankhattry.books to bookhouse, onlinestore; exports com.udayankhattry.members to test;
  • exports com.udayankhattry.books; exports com.udayankhattry.members to test;
  • export com.udayankhattry.books to bookhouse, onlinestore; export com.udayankhattry.members to test;
  • exports com.udayankhattry.books to bookhouse & onlinestore; exports com.udayankhattry.members to test;

Answer :exports com.udayankhattry.books to bookhouse, onlinestore; exports com.udayankhattry.members to test;


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error at Line n3 (Correct)
  • 0
  • Compilation error at Line n1
  • Compilation error at Line n2
  • 6
  • 1
  • Compilation error at Line n4
  • 5
  • 3

Answer :Compilation error at Line n3


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime (Correct)
  • 0.00
  • 0
  • 0.0
  • Compilation error

Answer :An exception is thrown at runtime

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 8


Consider below code of A.java file:



And the command:

java A.java


What is the result?


Options are :

  • AB
  • A (Correct)
  • ABC
  • ABCD
  • CD
  • None of the other options

Answer :A


In which of the Java versions, JPMS (Java Platform Module System) was introduced?


Options are :

  • Java 8
  • Java 11
  • Java 9 (Correct)
  • Java 10
  • Java 7

Answer :Java 9


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 14FNF
  • 124FINALLY (Correct)
  • Compilation error
  • 12IO
  • 124IO
  • 14FINALLY
  • 1234FINALLY

Answer :124FINALLY

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 21


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • A.
  • null
  • Compilation error at Line n2
  • A.B
  • A
  • Compilation error at Line n1
  • A.B.C.D (Correct)

Answer :A.B.C.D


Interface java.util.function.Predicate<T> declares below non-overriding abstract method:

boolean test(T t);


Given code of Test.java file:



Which of the following lambda expressions, if used to replace /*INSERT*/, prints [Jack, Liya] on to the console?


Options are :

  • (e) -> { e.getSalary() >= 10000; }
  • e - > e.getSalary() >= 10000
  • (Employee e) -> { return e.getSalary() >= 10000; } (Correct)
  • e -> { e.getSalary() >= 10000 }
  • e -> e.getSalary() >= 10000 (Correct)

Answer :(Employee e) -> { return e.getSalary() >= 10000; } e -> e.getSalary() >= 10000


Consider codes of 3 java files:





And below options:


1.

Add below import statement in Creator.java file:

import com.udayankhattry.galaxy.Planet;


2.

Add below import statement in Creator.java file:

import com.udayankhattry.ocp1.test.TestCreator


3.

Add below import statement in TestCreator.java file:

import com.udayankhattry.ocp1.Creator;


4.

Add below import statement in TestCreator.java file:

import com.udayankhattry.galaxy.Planet;


Which of the above options needs to be done so that on executing TestCreator class, "Planet: Earth" is printed on to the console?

Please note: Unnecessary imports are not allowed.


Options are :

  • 1, 2, 3 & 4 are needed
  • Only 1
  • 1 & 3 only (Correct)
  • 1, 3 & 4 only
  • Only 4
  • Only 2
  • 1 & 2 only
  • 3 & 4 only
  • Only 3

Answer :1 & 3 only

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 6


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • true
  • false
  • An exception is thrown at runtime (Correct)

Answer :An exception is thrown at runtime


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Lettuce Avocado Zucchini salad!
  • Lettuce Avocado Chickpea salad!
  • Lettuce salad! (Correct)
  • Lettuce Avocado salad!
  • None of the other options

Answer :Lettuce salad!


Below is the code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [apple, orange, mango, banana, grape] (Correct)
  • Compilation error
  • [apple, orange, grape, mango, banana, grape]
  • An exception is thrown at runtime
  • [apple, orange, mango, banana]

Answer :[apple, orange, mango, banana, grape]

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 44


Consider below code of Test.java file:



What is the result of compiling and executing Test class?


Options are :

  • B.VERAGE
  • B.V.RAG..
  • B.V.RAGE (Correct)
  • BEVERAGE
  • B.V.RAG.
  • Compilation error

Answer :B.V.RAGE


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 12 (Correct)
  • 2
  • 112
  • Compilation error
  • 1
  • 21
  • 121
  • 212
  • 221

Answer :12


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • a = 2, b = 4, c = 7, d = 9, res = false (Correct)
  • a = 2, b = 4, c = 8, d = 10, res = false
  • a = 2, b = 4, c = 7, d = 9, res = true
  • a = 3, b = 5, c = 8, d = 10, res = true
  • a = 2, b = 4, c = 8, d = 10, res = true
  • a = 3, b = 5, c = 8, d = 10, res = false

Answer :a = 2, b = 4, c = 7, d = 9, res = false

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 5


Consider below code fragment:



What is the output?


Options are :

  • MIST
  • MITS (Correct)
  • MISSS
  • MIT

Answer :MITS


Given below the directory/file structure on Windows platform:



Below is the code of Test.java file:


And below is the code of module-info.java file:


And the command executed from C:\

javac -d mods --module-source-path codes -m mymodule


What is the result?


Options are :

  • Given command compiles successfully
  • Compilation error in Test class, for reasons other than Line n1 (Correct)
  • Compilation error in Test class because of Line n1
  • Given javac command options are not correct

Answer :Compilation error in Test class, for reasons other than Line n1


Which of the following operators is used in lambda expressions?


Options are :

  • -> (Correct)
  • =>
  • - >
  • = >

Answer :->

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 31


Consider below codes of 4 java files:






Which of the following statements is correct?


Options are :

  • There is a compilation error in Dog.java file (Correct)
  • There is a compilation error in Animal.java file
  • There is no compilation error and on execution, Test class prints ANIMAL MOVING on to the console
  • There is a compilation error in Test.java file

Answer :There is a compilation error in Dog.java file


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • CharSequence
  • Compilation Error
  • String (Correct)
  • Object

Answer :String


How many of the below code statements, written inside main method will compile successfully?


1. var arr1 = new int[]{10};


2. var arr2 = new String[][] {};


3. var arr3 = new char[][] {{}};


4. var arr4 = {10, 20, 30};


5. var arr5 = new String[][] {new String[]{"LOOK"}, new String[] {"UP"}};


6. var [] arr6 = new int[] {2, 3, 4};


Options are :

  • None of the statements compile successfully
  • 4 statements compile successfully (Correct)
  • Only 1 statement compiles successfully
  • 2 statements compile successfully
  • 5 statements compile successfully
  • All 6 statements compile successfully
  • 3 statements compile successfully

Answer :4 statements compile successfully

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 41


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • true true
  • Line n2 causes compilation error
  • Line n1 causes compilation error
  • true false
  • false true (Correct)
  • false false

Answer :false true


Given code of Test.java file:



Which of the following options successfully replace /*INSERT*/ such that on execution, LAMBDA is printed on to the console?


Options are :

  • s -> s.toUpperCase(), "lambda"
  • s -> System.out.println(s.toUpperCase()), "lambda" (Correct)
  • s -> System.out.println(s.toUpperCase())
  • s -> { System.out.println(s.toUpperCase()) }, "lambda"

Answer :s -> System.out.println(s.toUpperCase()), "lambda"


Which of the following keywords is used to manually throw an exception?


Options are :

  • catch
  • thrown
  • throw (Correct)
  • throws

Answer :throw

Java Certification (1Z0-815) Exam Simulation [2020] Set 1


Consider below code snippet:



And the statements:

1. abstract class Work implements Workable

2. class Work implements Workable

3. interface Work extends Workable

4. abstract interface Work extends Workable

5. abstract class Work


How many statements can replace /*INSERT*/ such that there is no compilation error?


Options are :

  • One statement
  • Four statements
  • Five statements
  • Two statements
  • Three statements (Correct)

Answer :Three statements


Consider the code of TestStudent.java file:



What will be the result of compiling and executing TestStudent class?


Options are :

  • An exception is thrown at runtime
  • James:25
  • Line n2 causes compilation error
  • Line n1 causes compilation error
  • null:0 (Correct)

Answer :null:0


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Password10
  • Password19
  • Password 10
  • Password1234 (Correct)

Answer :Password1234

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 19


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Program compiles and executes successfully but nothing is printed on to the console (Correct)
  • Compilation error
  • KEEP CALM
  • An exception is thrown at runtime

Answer :Program compiles and executes successfully but nothing is printed on to the console


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • CR
  • CZAR
  • An exception is thrown at runtime
  • CAR (Correct)
  • Compilation error

Answer :CAR


Given codes of A.java file:



and B.java file:



One of the statements inside print() method causes compilation error.

Which of the below solutions will help to resolve compilation error?


Options are :

  • Comment the statement at Line 11
  • Comment the statement at Line 10
  • Comment the statement at Line 8
  • Comment the statement at Line 9 (Correct)

Answer :Comment the statement at Line 9

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 34


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime (Correct)
  • Compilation error
  • [Windsurfing, Aerobics, Archery, Diving]
  • [Windsurfing, Diving]

Answer :An exception is thrown at runtime


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Base: log()
  • Derived: log() (Correct)
  • Compilation error in Derived class
  • Compilation error in Test class

Answer :Derived: log()


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error (Correct)
  • KEEP IT
  • SIMPLE
  • KEEP IT SIMPLE

Answer :Compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 31


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • 23
  • 123 (Correct)
  • 12
  • 1
  • 2

Answer :123


Consider below code of Test.java file:



What is the result of compiling and executing above code?


Options are :

  • Runtime error
  • 97 b
  • a b
  • 97 98
  • a 98
  • Compilation error (Correct)

Answer :Compilation error


Consider below code of TestSquare.java file:



What will be the result of compiling and executing TestSquare class?


Options are :

  • An exception is thrown at runtime
  • It prints 0 on to the console
  • It prints 10 on to the console
  • It prints 5 on to the console (Correct)
  • It prints null on to the console
  • Compilation error

Answer :It prints 5 on to the console

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 13


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • Compilation error at Line n3
  • Compilation error at Line n2
  • It executes successfully and prints 22 on to the console
  • It executes successfully and prints 12 on to the console
  • It executes successfully and prints 102 on to the console (Correct)
  • It executes successfully and prints 202 on to the console

Answer :It executes successfully and prints 102 on to the console


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 24
  • 55
  • Compilation error
  • 25 (Correct)

Answer :25


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 101 202
  • 202 101
  • Compilation error (Correct)
  • 202
  • 101

Answer :Compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 17


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 2 2
  • Compilation Error
  • 2 1 (Correct)
  • None of the other options
  • 1 1

Answer :2 1


Consider below code of Counter.java file:



On executing Counter class, how many Counter objects are created in the memory?


Options are :

  • 2
  • 3
  • 4
  • 1 (Correct)

Answer :1

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 37


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • false : true true : false
  • false : true true : true
  • true : false true : false
  • false : false true : true
  • false : true false : true (Correct)

Answer :false : true false : true


Consider below code fragment:

private void emp() {}


And the statements:

1. Given code compiles successfully if it is used inside the class named 'emp'

2. Given code compiles successfully if it is used inside the class named 'Emp'

3. Given code compiles successfully if it is used inside the class named 'employee'

4. Given code compiles successfully if it is used inside the class named 'Employee'

5. Given code compiles successfully if it is used inside the class named 'Student'

6. Given code compiles successfully if it is used inside the class named '_emp_'


How many statements are true?


Options are :

  • Four statements
  • Two statements
  • Five statements
  • All six statements (Correct)
  • Three statements
  • Only one statement

Answer :All six statements


For the given code snippet:


List<String> list = new /*INSERT*/();


Which of the following options, if used to replace /*INSERT*/, compiles successfully?

Select ALL that apply.


Options are :

  • ArrayList<> (Correct)
  • List<>
  • ArrayList (Correct)
  • List

Answer :ArrayList<> ArrayList

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 14


Consider below code of Test.java file:



Which of the following options, if used to replace /*INSERT*/, will compile successfully and on execution will print 3 on to the console?

Select ALL that apply.


Options are :

  • int (Correct)
  • var
  • short (Correct)
  • byte
  • long (Correct)
  • double
  • float

Answer :int short long


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • 25
  • 24
  • 21 (Correct)
  • 22
  • 26
  • 23

Answer :21


Consider below code of Test.java file:



Which of the following commands will print 20 on to the console?

Select ALL that apply.


Options are :

  • java Test.java (Correct)
  • java --source 8 Test.java
  • java --source 10 Test.java (Correct)
  • Code causes compilation error and hence it will not execute
  • java --source 9 Test.java
  • java --source 11 Test.java (Correct)

Answer :java Test.java java --source 10 Test.java java --source 11 Test.java

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 40


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • S
  • K
  • A
  • L (Correct)
  • Runtime error

Answer :L


Consider below code of Test.java file:



What is the result of compiling and executing Test class?


Options are :

  • Compilation error at Line n2
  • Compilation error at Line n1
  • Compilation error at Line n3
  • 10 HELLO
  • HELLO (Correct)

Answer :HELLO


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [RED, GREEN]
  • Compilation error
  • An exception is thrown at runtime (Correct)
  • [RED, ORANGE, GREEN]
  • [RED, ORANGE]

Answer :An exception is thrown at runtime

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 44


What will be the result of compiling and executing Test class?



Options are :

  • 148
  • 128
  • -108 (Correct)
  • Compilation error

Answer :-108


Interface java.util.function.Predicate<T> declares below non-overriding abstract method:

boolean test(T t);


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Chair Table Sofa Bed Cabinet
  • Compilation error
  • Bed Cabinet
  • Chair Table Sofa (Correct)

Answer :Chair Table Sofa


Given below the directory/file structure on Windows platform:


File contents below:-


C:\src\com.udayankhattry.gifts\com\udayankhattry\gifts\Gift.java:


C:\src\com.udayankhattry.gifts\module-info.java:


C:\src\com.udayankhattry.game\com\udayankhattry\game\Game.java:


C:\src\com.udayankhattry.game\module-info.java:


C:\src\com.udayankhattry.test\com\udayankhattry\test\Test.java:


C:\src\com.udayankhattry.test\module-info.java:


And the below command to be executed from C:\

javac -d cls --module-source-path src -m com.udayankhattry.test


File C:\src\com.udayankhattry.game\module-info.java is incomplete, which of the following options replaces /*INSERT*/ such that given javac command successfully compiles the module code?


Options are :

  • require
  • exports
  • export
  • requires
  • requires transitive (Correct)

Answer :requires transitive

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 27


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Think (Correct)
  • Think_Twice
  • _Twice
  • None of the other options

Answer :Think


Consider below code of TestMessage.java file:



What will be the result of compiling and executing TestMessage class?


Options are :

  • null NEVER LOOK BACK!
  • LET IT GO! LET IT GO!
  • LET IT GO! NEVER LOOK BACK! (Correct)
  • NEVER LOOK BACK! NEVER LOOK BACK!
  • null null
  • Compilation error

Answer :LET IT GO! NEVER LOOK BACK!


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 1 2 java.lang.ArithmeticException
  • 1 java.lang.RuntimeException
  • 1 2 java.lang.RuntimeException
  • 1 java.lang.ClassCastException (Correct)
  • 1 java.lang.ArithmeticException

Answer :1 java.lang.ClassCastException

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 47


Given the code fragment:



What is the result?


Options are :

  • Compilation error
  • 2
  • 1
  • 0 (Correct)
  • 3

Answer :0


On Windows platform below directories/files are available:

1.

C:\codes\com.testing\module-info.java:


2.

C:\codes\com.testing\com\udayankhattry\ocp1\Test.java:


3.

C:\modules\


And the command executed from C:

javac -d modules --module-source-path codes --module com.testing


Which of the following changes enable above command to execute successfully (i.e. modular code to compile successfully)?


Options are :

  • Replace /*INSERT*/ with requires java.base; java.sql;
  • Replace /*INSERT*/ with requires java.*;
  • Replace /*INSERT*/ with requires java.io;
  • No changes are necessary, code as is compiles successfully
  • Replace /*INSERT*/ with requires java.sql; (Correct)

Answer :Replace /*INSERT*/ with requires java.sql;


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • POT
  • Compilation error
  • PET (Correct)
  • An exception is thrown by Line n2

Answer :PET

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 30


What will be the result of compiling and executing Test class?



Options are :

  • SWIMMING FOOTBALL
  • SWIMMING
  • RUNNING
  • RUNNING TENNIS SWIMMING FOOTBALL (Correct)

Answer :RUNNING TENNIS SWIMMING FOOTBALL


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • true
  • null
  • Compilation error (Correct)
  • An exception is thrown at runtime
  • false

Answer :Compilation error


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • m = 363 var = 363
  • m = 18 var = 363 (Correct)
  • Compilation error
  • m = 25 var = 363

Answer :m = 18 var = 363

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 48


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 10 Running
  • 64Running
  • 10Running (Correct)
  • 1234Running

Answer :10Running


Given code of Test.java file:



There is a compilation error in the code.

Which three modifications, done independently, print 1000 on to the console?


Options are :

  • Change Line n1 to private int var = 1000;
  • Change Line n4 to Parent obj = new Child(); (Correct)
  • Delete the method getVar() from the Child class
  • Change Line n5 to System.out.println(obj.getVar()); (Correct)
  • Change Line n3 to return var;
  • Delete the Line n2 (Correct)

Answer :Change Line n4 to Parent obj = new Child(); Change Line n5 to System.out.println(obj.getVar()); Delete the Line n2


Which of the following is the correct package declaration to declare Exam class in com.university.sem1 package?


Options are :

  • package com.university.sem1.*;
  • Package com.university.sem1;
  • package com.university.sem1.Test;
  • package com.university.sem1; (Correct)

Answer :package com.university.sem1;

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 8


Consider below codes of 4 java files:






What will be the result of compiling and executing Test class?


Options are :

  • It executes successfully and prints C on to the console
  • Compilation error
  • It executes successfully and prints A on to the console
  • An exception is thrown at runtime (Correct)
  • It executes successfully and prints B on to the console

Answer :An exception is thrown at runtime


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • Peace!
  • Compilation error
  • Inner Peace! (Correct)
  • Inner

Answer :Inner Peace!


Consider below code of Test.java file:



Which of the following statements is correct?


Options are :

  • Class C1 causes compilation error
  • Class Test causes compilation error (Correct)
  • Given code compiles successfully and on execution prints I1:JAVA on to the console
  • Given code compiles successfully and on execution prints C1:java on to the console
  • Interface I1 causes compilation error

Answer :Class Test causes compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 27


Consider below code of Test.java file:



Which of the following statements is correct for above code?


Options are :

  • Compilation error (Correct)
  • Infinite loop
  • Program compiles and executes successfully but produces no output
  • It will print "Good Morning!" once

Answer :Compilation error


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 8 (Correct)
  • 4
  • Line n1 causes compilation error
  • Line n2 causes Runtime error
  • 0
  • Line n1 causes Runtime error

Answer :8


Given below the directory/file structure on Windows platform:


Name of the module: com.udayankhattry.utility


and there are three public classes available:

com.udayankhattry.utility.FileUtility

com.udayankhattry.utility.StringUtility

com.udayankhattry.utility.internal.DateUtility


Currently module-info.java file is blank, which of the following options correctly describes the content of module-info.java file such that FileUtility and StringUtility classes are available for public use but not the DateUtility class?


Options are :

  • module com.udayankhattry.utility { exports com.udayankhattry.utility.*; }
  • module com.udayankhattry.utility { }
  • module com.udayankhattry.utility { exports com.udayankhattry.utility.internal; }
  • module com.udayankhattry.utility { exports com.udayankhattry.utility.FileUtility; exports com.udayankhattry.utility.StringUtility; not exports com.udayankhattry.utility.internal.DateUtility; }
  • module com.udayankhattry.utility { exports com.udayankhattry.utility; } (Correct)
  • module com.udayankhattry.utility { exports com.udayankhattry.utility; not exports com.udayankhattry.utility.internal; }
  • module com.udayankhattry.utility { exports com.udayankhattry.utility.FileUtility; exports com.udayankhattry.utility.StringUtility; }

Answer :module com.udayankhattry.utility { exports com.udayankhattry.utility; }

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 42


In a modular graph, [POSITION-1] are represented by nodes and [POSITION-2] between the modules are represented by arrows/edges.


Which of the following provide correct replacement for [POSITION-1] and [POSITION-2]?


Options are :

  • Replace [POSITION-1] with 'dependencies' and [POSITION-2] with 'modules'
  • Replace [POSITION-1] with 'packages' and [POSITION-2] with 'dependencies'
  • Replace [POSITION-1] with 'modules' and [POSITION-2] with 'dependencies' (Correct)
  • Replace [POSITION-1] with 'dependencies' and [POSITION-2] with 'classes'
  • Replace [POSITION-1] with 'dependencies' and [POSITION-2] with 'packages'
  • Replace [POSITION-1] with 'classes' and [POSITION-2] with 'dependencies'

Answer :Replace [POSITION-1] with 'modules' and [POSITION-2] with 'dependencies'


Consider the following interface declaration:



Which of the following incorrectly implements interface I1?


Options are :

  • public class C2 implements I1 { public void m1() throws java.io.FileNotFoundException{} }
  • public class C1 implements I1 { public void m1() {} }
  • public class C4 implements I1 { public void m1() throws Exception{} } (Correct)
  • public class C3 implements I1 { public void m1() throws java.io.IOException{} }

Answer :public class C4 implements I1 { public void m1() throws Exception{} }


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error (Correct)
  • ATAMAT
  • TOMATO
  • OTAMAT
  • TAMATA
  • TAMATO
  • OTAMOT

Answer :Compilation error

Java Certification (1Z0-815) Exam Simulation [2020] Set 1


Consider below code of Test.java file:



ASCII code of 'A' is 65 and 'B' is 66. What will be the result of compiling and executing Test class?


Options are :

  • 1 2 3
  • 65 66 (Correct)
  • 0 0
  • Compilation error
  • A B

Answer :65 66


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Method main(String []) causes compilation error
  • Method m() causes compilation error
  • CAUGHT SUCCESSFULLY is printed on to the console and program terminates successfully (Correct)
  • Program ends abruptly

Answer :CAUGHT SUCCESSFULLY is printed on to the console and program terminates successfully


Platform module ___________, is the most important module and every Java module requires it implicitly.


Options are :

  • java.base (Correct)
  • java.compiler
  • java.lang
  • java.se
  • java.logging

Answer :java.base

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 1


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [A, B, C, D] (Correct)
  • [A, D, B, C]
  • [A, D]
  • [A, B, C]

Answer :[A, B, C, D]


Which of the following are Java Exception classes?

Select 3 options.


Options are :

  • IllegalArgumentException (Correct)
  • NumberFormatException (Correct)
  • ArrayIndexException
  • NullException
  • ClassCastException (Correct)

Answer :IllegalArgumentException NumberFormatException ClassCastException


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • % $$ *** @@@@ #####
  • % $$ (Correct)
  • %
  • % $$ *** @@@@
  • % $$ ***

Answer :% $$

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 37


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Udayan_Khattry
  • UDAYAN_KHATTRY
  • Udayan_KHATTRY (Correct)
  • UDAYAN_Khattry

Answer :Udayan_KHATTRY


Below is the code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [Okinawa, Manila, Batam]
  • [Austin, Okinawa, Manila, Batam, Giza]
  • [Okinawa, Manila, Batam, Giza] (Correct)
  • [Okinawa, Giza, Manila, Batam]
  • [Austin, Okinawa, Manila, Batam]
  • [Austin, Okinawa, Giza, Manila, Batam, Giza]
  • An exception is thrown at runtime
  • Compilation error

Answer :[Okinawa, Manila, Batam, Giza]


For the given code:



Which of the following options successfully replace /*INSERT*/ such that on execution, WINNERS NEVER QUIT is printed on to the console?

Select ALL that apply.


Options are :

  • Printable obj = (String msg) -> {System.out.println(msg);}; (Correct)
  • Printable obj = (msg) -> System.out.println(msg); (Correct)
  • Printable obj = String msg -> {System.out.println(msg);};
  • Printable obj = (String msg) -> {System.out.println(msg); return;}; (Correct)
  • Printable obj = msg -> System.out.println(msg); (Correct)
  • Printable obj = msg -> {System.out.println(msg)};
  • Printable obj = x -> System.out.println(x); (Correct)
  • Printable obj = y - > System.out.println(y);
  • Printable obj = (msg) -> {System.out.println(msg);}; (Correct)

Answer :Printable obj = (String msg) -> {System.out.println(msg);}; Printable obj = (msg) -> System.out.println(msg); Printable obj = (String msg) -> {System.out.println(msg); return;}; Printable obj = msg -> System.out.println(msg); Printable obj = x -> System.out.println(x); Printable obj = (msg) -> {System.out.println(msg);};

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 6


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 123 (Correct)
  • 1.2.3
  • An exception is thrown at runtime
  • Compilation error
  • 3

Answer :123


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • false:false:true:true
  • true:true:true:true
  • false:true:true:true
  • Compilation error (Correct)
  • false:false:true:false

Answer :Compilation error


Consider below codes of 4 java files:






Which of the following statements is correct?


Options are :

  • Line n4 causes compilation error (Correct)
  • Line n1 causes compilation error
  • There is no compilation error
  • Line n2 causes compilation error
  • Line n3 causes compilation error

Answer :Line n4 causes compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 36


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • GROUP
  • PLAY
  • An exception is thrown at runtime
  • Compilation error
  • PLAY-GROUP
  • PLAY-null (Correct)
  • -

Answer :PLAY-null


Given below the directory/file structure on Windows platform:


Below are the file contents:-


C:\codes\currency\module-info.java:


C:\codes\currency\com\udayankhattry\ocp1\Currency.java:


And consider the command to be executed from C:\

javac -d classes _______________ codes -m currency


Which of the options can be used to fill above blank such that there is no error on executing above command?


Options are :

  • --path
  • --source-code-path
  • --module-path
  • -p
  • --module-source-path (Correct)
  • --source

Answer :--module-source-path


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error at Line n1 (Correct)
  • Compilation error at Line n2
  • NOT THROWING ANY EXCEPTION
  • Compilation error at Line n3

Answer :Compilation error at Line n1

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 46


Consider below code of Child.java file:



And the command:

java Child.java


What is the result?


Options are :

  • Child
  • Parent Child
  • Above command causes error
  • Child Parent
  • Parent (Correct)

Answer :Parent


On Windows platform below directories/files are available:


Contents of module-info.java file:


Contents of Main.java file:


Which of the following jar commands executed from C:\, will package the above module such that the execution of the command:

java -p jars -m com.udayankhattry.modularity

prints MODULAR APPLICATION on to the console?


Options are :

  • jar -cf jars\test.jar -C classes\com.udayankhattry.modularity .
  • jar -cfe jars\test.jar com.udayankhattry.ocp1.Main -C classes\com.udayankhattry.modularity . (Correct)
  • jar jars\test.jar -C classes\com.udayankhattry.modularity .
  • jar jars\test.jar com.udayankhattry.ocp1.Main -C classes\com.udayankhattry.modularity .

Answer :jar -cfe jars\test.jar com.udayankhattry.ocp1.Main -C classes\com.udayankhattry.modularity .


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error at Line n2 (Correct)
  • 3
  • 2
  • 0
  • Compilation error at Line n1

Answer :Compilation error at Line n2

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 12


Given the following definitions of the class Insect and the interface Flyable, the task is to declare a class Mosquito that inherits from the class Insect and implements the interface Flyable.


Select the correct option to accomplish this task:


Options are :

  • class Mosquito extends Insect, Flyable{}
  • class Mosquito implements Insect extends Flyable{}
  • class Mosquito extends Insect implements Flyable{} (Correct)
  • class Mosquito implements Insect, Flyable{}

Answer :class Mosquito extends Insect implements Flyable{}


Given code of Test.java file:



Which of the following statements is correct?


Options are :

  • Given code compiles successfully
  • Line n2 causes compilation error
  • There is a compilation error in class A
  • Line n3 causes compilation error
  • There is a compilation error in interface M
  • Line n1 causes compilation error (Correct)

Answer :Line n1 causes compilation error


Your Vendor has provided you a modular jar to test the database connection API.

Below are the Jar details:

Jar File name: dbconnection.jar

Module name: dbconnection

Module-descriptor of this jar contains:


You have to write the module and test code, which of the following is correct module descriptor?

Please note that commented line in each option represents the module descriptor file name.


Options are :

  • //module-info.java module dbtester { requires com.database.util; }
  • //module-info.java module dbtester { }
  • //module-info.java module mymodule { requires dbconnection; }
  • //module-info.java module dbtester { requires dbconnection; } (Correct)
  • //module-desc.java module dbtester { requires dbconnection; }
  • //module-info.java module mymodule { requires com.database.util; }

Answer ://module-info.java module dbtester { requires dbconnection; }

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 6


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [7, 17, 5] (Correct)
  • Compilation error
  • [100, 7, 50, 17, 10, 5]
  • [100, 50, 10]
  • Runtime Exception

Answer :[7, 17, 5]


Below is the code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • false
  • Runtime exception
  • Compilation error (Correct)
  • true

Answer :Compilation error


Consider below code snippet available in the same package:



Which of the following declarations/definitions can replace /*INSERT*/ such that there is no compilation error?

Select ALL that apply.


Options are :

  • abstract void travel(String beach); (Correct)
  • void travel(String beach) throws java.io.IOException {}
  • public void travel() throws RuntimeException {} (Correct)
  • public void travel(String beach) throws Exception {}
  • public void travel(Object obj) {} (Correct)
  • public abstract void travel(); (Correct)
  • abstract void travel(); (Correct)

Answer :abstract void travel(String beach); public void travel() throws RuntimeException {} public void travel(Object obj) {} public abstract void travel(); abstract void travel();

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 3


Which one of these top level classes cannot be sub-classed?


Options are :

  • final class Electronics {} (Correct)
  • private class Car {}
  • abstract class Cat {}
  • class Dog {}

Answer :final class Electronics {}


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Imperfectly Perfect
  • Compilation error
  • Imperfectly Perfect Imperfectly Perfect (Correct)
  • Imperfectly Perfect Imperfectly Perfect Imperfectly Perfect

Answer :Imperfectly Perfect Imperfectly Perfect


Consider below code of Apple.java file:



For the class Apple, which option, if used to replace /*INSERT*/, will print GREEN on to the console?


Options are :

  • color = GREEN;
  • this.color = color; (Correct)
  • this.color = GREEN;
  • color = color;

Answer :this.color = color;

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 27


Consider below code of Test.java file:



What is the result of compiling and executing Test class?


Options are :

  • 0
  • false
  • 1
  • Compilation error (Correct)
  • true

Answer :Compilation error


Given code of Test.java file:



Which of the following interface definitions can replace /*INSERT*/ such that there is no compilation error?

Select ALL that apply.


Options are :

  • interface MyInterface { StringBuilder m(); }
  • interface MyInterface { Object toStr(); boolean equals(MyInterface); }
  • interface MyInterface { CharSequence test(); } (Correct)
  • interface MyInterface { String toStr(); String toString(); } (Correct)
  • interface MyInterface { Object toStr(); String toString(); static void print(String str) { System.out.println(str); } } (Correct)
  • interface MyInterface { String toStr(); } (Correct)
  • interface MyInterface { String toString(); }

Answer :interface MyInterface { CharSequence test(); } interface MyInterface { String toStr(); String toString(); } interface MyInterface { Object toStr(); String toString(); static void print(String str) { System.out.println(str); } } interface MyInterface { String toStr(); }


Below is the code of Test.java file.


Below are the definitions of main method:

1.


2.


3.


4.


5.


How many definitions of main method can replace /* INSERT */ such that on executing Test class, "Java Rocks!" is printed on to the console?


Options are :

  • Only three definitions
  • Only one definition
  • All 5 definitions
  • Only two definitions (Correct)
  • Only four definitions

Answer :Only two definitions

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 44


super keyword in java is used to:


Options are :

  • refer to the object of parent class (Correct)
  • refer to the static method of the class
  • refer to the static variable of the class
  • refer to the object of current class

Answer :refer to the object of parent class


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [Watch, Arrow, Anchor, Drum]
  • An exception is thrown at runtime
  • Compilation error
  • [Watch, Drum] (Correct)

Answer :[Watch, Drum]


Which of the following is not a valid array declaration?


Options are :

  • int [] arr1 = new int[8];
  • int [] arr3 [] = new int[8][];
  • int arr4[][] = new int[][8]; (Correct)
  • int [][] arr2 = new int[8][8];

Answer :int arr4[][] = new int[][8];

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 4


Given code of Test.java file:


And the commands:

javac Test.java

java Test Good


What is the result?


Options are :

  • Good
  • Good Day!
  • An exception is thrown at runtime (Correct)
  • Compilation Error

Answer :An exception is thrown at runtime


Consider the code of TestEmployee.java file:



What will be the result of compiling and executing TestEmployee class?


Options are :

  • Compilation error at Line n2
  • Compilation error at Line n1 (Correct)
  • null:0
  • Michael:22
  • An exception is thrown at runtime

Answer :Compilation error at Line n1


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An Exception is thrown at runtime
  • 0 1 2 (Correct)
  • 2 1 0
  • Compilation error

Answer :0 1 2

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 18


Given code of Test.java file:



Which of the following options can replace /*INSERT*/ such that output is:

EARTH

MOON

SUN

JUPITER


Select ALL that apply.


Options are :

  • Arrays.asList(arr) (Correct)
  • ArrayList.of(arr)
  • new ArrayList<>(ArrayList.of(arr))
  • List.of(arr)
  • new ArrayList<>(List.of(arr)) (Correct)

Answer :Arrays.asList(arr) new ArrayList<>(List.of(arr))


Given code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • It compiles successfully and on execution prints below: Good Morning! Good Morning! Good Morning!
  • It compiles successfully and on execution prints below: Good Night! Good Night! Good Night! (Correct)
  • It compiles successfully and on execution prints below: Good Night! Good Afternoon! Good Morning!
  • Compilation error
  • An exception is thrown at runtime

Answer :It compiles successfully and on execution prints below: Good Night! Good Night! Good Night!


Consider below codes of 3 java files:





What will be the result of compiling and executing Test class?


Options are :

  • Compilation error in Test.java file
  • It executes successfully but nothing is printed on to the console
  • It executes successfully and prints ANIMAL-DOG on to the console
  • It executes successfully and prints DOG on to the console
  • Compilation error in Dog.java file (Correct)
  • Compilation error in Animal.java file

Answer :Compilation error in Dog.java file

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 35


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • It executes successfully and prints 30 on to the console (Correct)
  • It executes successfully and prints 10 on to the console
  • It executes successfully and prints 20 on to the console
  • Line n1 causes compilation error
  • Line n2 causes compilation error

Answer :It executes successfully and prints 30 on to the console


Consider below code of Test.java file:



Which option, if used to replace /*INSERT*/, on execution will print ACE on to the console?


Options are :

  • int n = 1; n < arr.length; n += 2
  • int n = 0; n < arr.length; n += 2 (Correct)
  • int n = 1; n < arr.length; n += 1
  • int n = 0; n < arr.length; n += 1

Answer :int n = 0; n < arr.length; n += 2


Consider below code of Test.java file:



And below combination of x and y values:

1. x = 6, y = 6

2. x = 2, y = 5

3. x = 4, y = 7

4. x = 7, y = 7

5. x = 8, y = 8

6. x = 0, y = 0

7. x = -1, y = -1


How many of above x,y pair(s) can replace x and y at Line n1 such that Test.java file compiles successfully?


Options are :

  • 5 pairs
  • 4 pairs
  • 2 pairs
  • All 7 pairs (Correct)
  • 1 pair
  • 6 pairs
  • 3 pairs

Answer :All 7 pairs

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 5


Given code of Test.java file:



Which of the block of codes can be used to replace /*INSERT*/ such that there is no compilation error?

Select ALL that apply.


Options are :

  • try { save(); log(); } catch(Exception | RuntimeException ex) {}
  • try { save(); log(); } catch(IOException | Exception ex) {}
  • try { save(); log(); } catch(SQLException | IOException ex) {} (Correct)
  • try { save(); log(); } catch(Exception ex) {} (Correct)
  • try { save(); log(); } catch(IOException | SQLException ex) {} (Correct)
  • try { save(); log(); } catch(SQLException | Exception ex) {}

Answer :try { save(); log(); } catch(SQLException | IOException ex) {} try { save(); log(); } catch(Exception ex) {} try { save(); log(); } catch(IOException | SQLException ex) {}


Consider below code of TestBook.java file:



What will be the result of compiling and executing above code?


Options are :

  • null null
  • Compilation error in Book class
  • Head First Java Kathy Sierra
  • Compilation error in TestBook class (Correct)

Answer :Compilation error in TestBook class


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • It compiles successfully and on execution prints 7 on to the console (Correct)
  • Line n2 causes compilation error
  • It compiles successfully and on execution prints FRIENDS on to the console
  • Line n3 causes compilation error
  • Line n1 causes compilation error

Answer :It compiles successfully and on execution prints 7 on to the console

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 25


Consider below code of Test.java file:


Location of Test.java file:


You are currently at 'codes' folder.

F:\codes>


Which of the following javac commands, typed from above location, will generate Test.class file structure under 'classes' directory?


Options are :

  • javac -d classes\ Test.java
  • javac -d classes\ com.udayankhattry.ocp1.Test.java
  • javac -d classes\ src\com.udayankhattry.cop1.Test.java
  • javac classes\ src\com\udayankhattry\ocp1\Test.java
  • javac -d classes\ src\Test.java
  • javac -d classes\ src\com\udayankhattry\ocp1\Test.java (Correct)

Answer :javac -d classes\ src\com\udayankhattry\ocp1\Test.java


Given code of Test.java file:



What is the result of compiling and executing Test class?


Options are :

  • Line n2 causes compilation error
  • 30 is printed on to the console
  • Line n3 causes compilation error (Correct)
  • Line n1 causes compilation error

Answer :Line n3 causes compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 30


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • "Exception!!!" is printed on to the console and program terminates abruptly
  • "Exception!!!" is printed on to the console and program terminates successfully
  • "Exception!!!" and "Main ends!!!" are printed on to the console and program terminates successfully
  • Program terminates abruptly (Correct)
  • "Main ends!!!" is printed on to the console and program terminates successfully

Answer :Program terminates abruptly


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [ONE, TWO]
  • [ONE, TWO, THREE]
  • An exception is thrown at runtime
  • Compilation error (Correct)
  • [ONE, TWO, THREE, THREE]

Answer :Compilation error


Consider below code of Test.java file:



What is the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • USER-GENERATED (Correct)
  • Compilation error
  • USER GENERATED
  • -

Answer :USER-GENERATED

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 3


Consider below codes of 3 java files:





Which of the following statements are correct?

Select ALL that apply.


Options are :

  • There is a compilation error in Buyable.java file
  • There is a compilation error in Book.java file
  • There is a compilation error at Line n2 (Correct)
  • There is a compilation error at Line n4 (Correct)
  • There is a compilation error at Line n3
  • There is a compilation error at Line n1

Answer :There is a compilation error at Line n2 There is a compilation error at Line n4


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [Walnut, Date]
  • Compilation error
  • An exception is thrown at runtime (Correct)
  • [Walnut, Apricot, Almond, Date]

Answer :An exception is thrown at runtime


Consider below code of Test.java file:



Currently above code causes compilation error.

Which of the options can successfully replace //TODO such that on executing Test class, output is TEXT,25?


Options are :

  • super.pages = pages; this(type);
  • this(type); super.pages = pages; (Correct)
  • super(pages); this(type);
  • this(type); super(pages);

Answer :this(type); super.pages = pages;

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 8


Consider below code of TestNewsPaper.java file:



On executing TestNewsPaper class, how many objects of NewsPaper class will be eligible for Garbage Collection at Line n4?


Options are :

  • 2 (Correct)
  • 0
  • 1
  • 3

Answer :2


Given below the directory/file structure on Windows platform:



Below is the code of C:\source_files\com.udayan.test\module-info.java file:


and below is the code of C:\source_files\com.udayan.test\com\udayankhattry\ocp1\Main.java file:


And the below two commands executed from C:\

javac -d class_files --module-source-path source_files --module com.udayan.test

java -p class_files --module com.udayan.test/com.udayankhattry.ocp1.Main


What is the result?


Options are :

  • An exception is thrown at runtime
  • Compilation error in Main.java file
  • Compilation error in module-info.java file
  • MODULE:REQUIRES:EXPORTS is printed on to the console (Correct)

Answer :MODULE:REQUIRES:EXPORTS is printed on to the console


Given code of Test.java file:



Which of the following statements is correct?


Options are :

  • Interface WordDocument causes compilation error
  • Class Word causes compilation error (Correct)
  • Interface Document causes compilation error
  • Test class compiles successfully and on execution prints TEXT on to the console

Answer :Class Word causes compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 38


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • null
  • Line 4 causes compilation failure
  • Line 8 causes compilation failure (Correct)
  • An exception is thrown at runtime by Line 6
  • Line 2 causes compilation failure

Answer :Line 8 causes compilation failure


Consider below code of Test.java file:



Which of the following options, if used to replace /*INSERT*/, will compile successfully and on execution will print true on to the console?

Select ALL that apply.


Options are :

  • s1.equalsIgnoreCase(s2) (Correct)
  • s1.equals(s2.toUpper())
  • s1.length() == s2.length() (Correct)
  • s1.contentEquals(s2)
  • s1.equals(s2)
  • s2.equals(s1.toLower())

Answer :s1.equalsIgnoreCase(s2) s1.length() == s2.length()


Consider codes of 3 java files:





For the class Shop, which options, if used to replace /*INSERT*/, will resolve all the compilation errors? Select 2 options.


Options are :

  • import orders.*; import orders.items.*; (Correct)
  • import orders.*;
  • import orders.Order; import orders.items.Item; (Correct)
  • import orders.*; import items.*;
  • import orders.items.*;

Answer :import orders.*; import orders.items.*; import orders.Order; import orders.items.Item;

Java Certification (1Z0-815) Exam Simulation [2020] Set 1


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • INT VERSION INT VERSION
  • INT VERSION CHAR VERSION (Correct)
  • Compilation error
  • CHAR VERSION CHAR VERSION
  • CHAR VERSION INT VERSION

Answer :INT VERSION CHAR VERSION


Consider below code of Test.java file:



What is the result of compiling and executing above code?


Options are :

  • 1020 AB 66
  • 30 AB A1
  • Compilation error (Correct)
  • Runtime error
  • 1020 AB A1
  • 30 AB 66

Answer :Compilation error


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • false false
  • true false
  • Compilation error (Correct)
  • false true
  • true true

Answer :Compilation error

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 2


Given below the directory/file structure on Windows platform:


Contents of C:\dir1\shopping\module-info.java file:


Contents of C:\dir1\shopping\com\shopping\online\Product.java file:


And the command executed from C:\

javac -d dir2 --module-source-path dir1 -m shopping


Which of the following statements is correct?


Options are :

  • Code compiles successfully and path of generated module-info.class file is C:\dir2\module-info.class
  • Code compiles successfully and path of generated module-info.class file is C:\dir2\shopping\com\shopping\online\module-info.class
  • Code compiles successfully and path of generated module-info.class file is C:\dir2\shopping\module-info.class (Correct)
  • javac command fails as module-info.java file is not valid

Answer :Code compiles successfully and path of generated module-info.class file is C:\dir2\shopping\module-info.class


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • EXPO
  • Compilation error
  • Runtime error (Correct)
  • EPXO
  • EXP
  • EPX

Answer :Runtime error


What is the purpose of below lambda expression?


(x, y) -> x + y;


Options are :

  • It accepts two int arguments, adds them and returns the int value
  • It accepts a String and an int arguments, concatenates them and returns the String instance
  • It accepts two String arguments, concatenates them and returns the String instance
  • Not possible to define the purpose (Correct)

Answer :Not possible to define the purpose

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 5


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [DIWALI, CHRISTMAS, EID]
  • An exception is thrown at runtime (Correct)
  • Compilation error
  • [DIWALI, CHRISTMAS]
  • []

Answer :An exception is thrown at runtime


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • true
  • An exception is thrown at runtime
  • false (Correct)
  • Compilation error

Answer :false


Consider below code of Test.java file:



Which of the following is true for the above code?


Options are :

  • 0 is printed on to the console
  • null is printed on to the console
  • Above code causes compilation error
  • An exception is thrown at runtime (Correct)

Answer :An exception is thrown at runtime

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 32


What will be the result of compiling and executing Test class?



Options are :

  • 25
  • Program executes successfully but nothing is printed on to the console
  • 27
  • 26 (Correct)

Answer :26


Given code of Test.java file:



Which of the following needs to be done so that LIGHT is printed on to the console?


Options are :

  • Replace Line n5 with new Car().speed((byte...)b);
  • Delete Line n1, Line n2 and Line n3 (Correct)
  • Replace Line n4 with byte... b = 10;
  • No changes are required as given code prints LIGHT on execution

Answer :Delete Line n1, Line n2 and Line n3


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 6
  • Compilation error at Line n1
  • Compilation error at Line n2 (Correct)
  • 4
  • 21
  • 10
  • 17
  • Compilation error at Line n3
  • 0

Answer :Compilation error at Line n2


Which of the following statement declares a constant field in Java?


Options are :

  • const int x = 10;
  • static int x = 10;
  • final static int x = 10; (Correct)
  • int x = 10;

Answer :final static int x = 10;


For the given code fragment:



Which 2 modifications, done independently, enable the code to compile?


Options are :

  • Make the play() method of FootballPlayer class public (Correct)
  • Make the play() method of Player class public
  • Make the run() method of FootballPlayer class public
  • Make the run() method of Player class public
  • Make the play() method of FootballPlayer class protected (Correct)

Answer :Make the play() method of FootballPlayer class public Make the play() method of FootballPlayer class protected


Consider below code snippet:



What is the result?


Options are :

  • Compilation error
  • null
  • true (Correct)
  • false

Answer :true


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • Compilation Error in Test class
  • It prints KEEP_KEEP_GOING_ on to the console
  • It prints GOING_KEEP_ on to the console
  • It prints GOING_ on to the console
  • Compilation Error in Super class
  • Compilation Error in Base class
  • It prints KEEP_GOING_ on to the console (Correct)

Answer :It prints KEEP_GOING_ on to the console


Given below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Line n3 causes compilation error
  • Code compiles successfully and on execution prints SPORT-MAD on to the console
  • An exception is thrown at runtime
  • Line n7 causes compilation error
  • Line n2 causes compilation error
  • Line n1 causes compilation error
  • Code compiles successfully and on execution prints SPORTMAD on to the console (Correct)

Answer :Code compiles successfully and on execution prints SPORTMAD on to the console


Which of the following is a valid module descriptor file contents for 'agriculture' module?


Options are :

  • module agriculture { } module farming { }
  • module agriculture { import java.se; }
  • import java.lang.*; module agriculture { } (Correct)
  • module agriculture { imports java.se; }
  • module agriculture extends java.se{ }
  • None of the other options
  • public module agriculture { }

Answer :import java.lang.*; module agriculture { }


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Line n1 causes compilation error
  • [A, E, I, O, U]
  • [A, E, I, O, U, A, E, I, O] (Correct)
  • [A, E, I, O, U, A, E, I, O, U]
  • An exception is thrown at runtime by Line n2
  • Line n2 causes compilation error

Answer :[A, E, I, O, U, A, E, I, O]


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • true:true
  • false:false
  • An Exception is thrown at runtime
  • null:null (Correct)

Answer :null:null


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Infinite loop (Correct)
  • 1 2 3 4
  • 1 2 3 4 5
  • 2 3 4 5

Answer :Infinite loop


Below is the code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Exception is thrown at runtime
  • [25]
  • [25, 15, 25] (Correct)
  • [15, 25, 25]
  • [25, 25]
  • Compilation error

Answer :[25, 15, 25]


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 112
  • 012
  • Compilation error
  • 12
  • 011 (Correct)
  • 01

Answer :011


For the class Test, which of the following options, if used to replace /*INSERT*/, will print "BUY 2 GET 1 FREE" on to the console?



Options are :

  • Integer day = 3;
  • int day = '3'; (Correct)
  • int day = 3;
  • None of the other options

Answer :int day = '3';


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 33 (Correct)
  • 34
  • Compilation error
  • 33 32
  • 32

Answer :33


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • AWESOME
  • SOME
  • Compilation error (Correct)
  • AWE
  • Program ends abruptly

Answer :Compilation error


What will be the result of compiling and executing Test class?



Options are :

  • 25-60 (Correct)
  • 25-25
  • 35-60
  • 35-25

Answer :25-60


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • B B C D
  • An exception is thrown at runtime
  • Compilation error
  • A B C D
  • A E C D
  • B E C D (Correct)
  • E E C D

Answer :B E C D


What will be the result of compiling and executing Test class?



Options are :

  • Compilation error (Correct)
  • In default
  • var is 100
  • var is 200

Answer :Compilation error


Given:



Which of the following is not a valid statement based on above code?


Options are :

  • A obj2 = new B();
  • A obj4 = new A();
  • B obj3 = new B();
  • B obj1 = new A(); (Correct)

Answer :B obj1 = new A();


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • Line n2 causes compilation error
  • Test class executes successfully and prints: DEER JUMPS DEER JUMPS TO 5 FEET (Correct)
  • Line n3 causes compilation error
  • Line n1 causes compilation error

Answer :Test class executes successfully and prints: DEER JUMPS DEER JUMPS TO 5 FEET


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • 4:4
  • Compilation error at Line n3
  • 0:4 (Correct)
  • 4:0
  • 0:0
  • Compilation error at Line n4

Answer :0:4


Consider below code of Test.java file:



And the command:

java Test.java


What is the result?


Options are :

  • Test2
  • Above command causes error
  • Test1 Test2 Test3
  • Test1
  • Test3 (Correct)
  • Test3 Test2 Test1

Answer :Test3


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • [Counter-10]
  • [Counter-5] (Correct)
  • Compilation error

Answer :[Counter-5]


Consider incomplete code of M.java file



Following options are available to fill the above blank:

1. public

2. private

3. protected

4. final

5. abstract


How many above options can be used to fill above blank (separately and not together) such that there is no compilation error?


Options are :

  • Only four options
  • All five options
  • Only three options
  • Only one option
  • Only two options (Correct)

Answer :Only two options


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • 100
  • 20 (Correct)
  • Exception is thrown at runtime

Answer :20


Consider below code of Test.java file:



Range of byte data type is from -128 to 127.


Following options are available to replace /*INSERT*/:

1. var = var - 1

2. var = var + 1

3. ++var

4. --var

5. var *= 2

6. var -= 10

7. var += 2

8. var


How many above options can be used to replace /*INSERT*/ (separately and not together) such that there is no compilation error?


Options are :

  • Three options only
  • Five options only
  • Four options only
  • All eight options
  • One option only
  • Two options only
  • Seven options only
  • Six options only (Correct)

Answer :Six options only


Given below the directory/file structure on Windows platform:



Below are the file contents:-


C:\source\tools\module-info.java:


C:\source\tools\com\it\tools\Tools.java:


C:\source\tools\com\it\tools\Eclipse.java:


And below javac command is executed from C:\

javac -d classes --module-source-path source -m tools


What is the result?


Options are :

  • Code compiles but with a warning for Line n1 only
  • Compilation error for Eclipse.java file
  • Compilation error for both Line n1 and Line n3
  • Compilation error for Line n3 only
  • Code compiles but with a warning for Line n3 only
  • Compilation error for Line n1 only (Correct)
  • Code compiles without any warning
  • Code compiles but with a warning for both Line n1 and Line n3

Answer :Compilation error for Line n1 only


On Windows platform below directories/files are available:

C:\src\com.training\com\udayankhattry\ocp1\Training.java


Which of the following correctly defines the module descriptor for 'com.training' module?

Please note that commented line in each option represents the module descriptor file name.


Options are :

  • //module-descriptor.java module com.training { requires java.base; }
  • //Module.java module training { }
  • //Module-Info.java module com.training { }
  • //module-descriptor.java module com.training { }
  • //module.java module com.training { requires java.base; }
  • //module-info.java module com.training { } (Correct)

Answer ://module-info.java module com.training { }


Given code of Test.java file:



Which of the following statements is true for above code?


Options are :

  • Line n4 causes compilation error
  • Line n2 causes compilation error (Correct)
  • Line n3 causes compilation error
  • Line n1 causes compilation error
  • It executes successfully and prints M on to the console

Answer :Line n2 causes compilation error


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 26.0 1.0
  • 26.5 0.0
  • 26.5 1.0 (Correct)
  • 26 1

Answer :26.5 1.0


Given below the directory/file structure on Windows platform:



Below are the file details:-


C:\src\x\com\circus\Animal.java:


C:\src\x\com\circus\Lion.java:


C:\src\x\module-info.java:


C:\src\y\com\circus\tricks\Tricks.java:


C:\src\y\module-info.java:


Which of following commands if executed from C:\ will compile both the modules x and y?


Options are :

  • javac -d bin --module-source-path src --module x
  • javac -d bin --module-source-path src --module y (Correct)
  • javac -d bin --module-source-path src --module x;y
  • javac -d bin --module-source-path src --module *

Answer :javac -d bin --module-source-path src --module y


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • It causes compilation error at multiple statements
  • It prints XY on to the console and program terminates abruptly
  • It prints XY on to the console and program terminates successfully
  • It throws an exception at runtime (Correct)
  • It causes compilation error at single statement

Answer :It throws an exception at runtime


Fill in the blanks for the definition of java.lang.Error class:

public class java.lang.Error extends ________________ {...}


Options are :

  • Exception
  • Throwable (Correct)
  • RuntimeException

Answer :Throwable


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error (Correct)
  • GAME ON is printed to the console and program ends normally
  • GAME ON is printed to the console, stack trace is printed and then program ends normally
  • GAME ON is printed to the console, stack trace is printed and then program ends abruptly

Answer :Compilation error


Consider below code of Test.java file:



Which of the following statements is correct?


Options are :

  • Interface Perishable2 causes compilation error
  • Class Test causes compilation error
  • Given code compiles successfully and on execution Test class prints 1 on to the console
  • Given code compiles successfully and on execution Test class prints 2 on to the console (Correct)
  • Class Milk causes compilation error

Answer :Given code compiles successfully and on execution Test class prints 2 on to the console


Does JDK 11 release offer separate JRE?



Options are :

  • Yes
  • No (Correct)

Answer :No


Consider below code snippet:



And the definitions of get() method:

1. List<Father> get() {return null;}

2. ArrayList<Father> get() {return null;}

3. List<Son> get() {return null;}

4. ArrayList<Son> get() {return null;}

5. List<GrandSon> get() {return null;}

6. ArrayList<GrandSon> get() {return null;}

7. List<Object> get() {return null;}

8. ArrayList<Object> get() {return null;}


How many definitions of get() method can replace /*INSERT*/ such that there is no compilation error?


Options are :

  • Eight definitions
  • Two definitions (Correct)
  • One definition
  • Four definitions
  • Three definitions
  • Five definitions
  • Seven definitions
  • Six definitions

Answer :Two definitions


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Exception is thrown at runtime
  • 200
  • Compilation error (Correct)
  • 50

Answer :Compilation error


Consider below code of Test.java file:



Which of the following statements is correct for above code?


Options are :

  • Compiles successfully and on execution prints SLOW- in infinite loop
  • Unreachable code compilation error
  • Compiles successfully and on execution prints SLOW-DOWN (Correct)
  • Compiles successfully and on execution prints DOWN

Answer :Compiles successfully and on execution prints SLOW-DOWN


Given below the directory/file structure on Windows platform:




Below is the code of Calculator.java file:


And below is the code of module-info.java file:


Which of the following set of commands if executed from C:, successfully compile and execute the given code such that output is: 60?


Options are :

  • javac -d out --module-source-path src --module calculator java -p out -m calc/com.udayankhattry.ocp1.Calculator
  • javac -d out --module-source-path src --module calc java -p out -m calculator/com.udayankhattry.ocp1.Calculator
  • javac -d out\calc-module src\calculator\com\udayankhattry\ocp1\Calculator.java java --module-path out --module calculator/com.udayankhattry.ocp1.Calculator
  • javac -d out --module-source-path src --module calc-module java -p out -m calc-module/com.udayankhattry.ocp1.Calculator
  • javac -d out\calc-module src\calculator\com\udayankhattry\ocp1\Calculator.java src\calculator\module-info.java java --module-path out --module calc/com.udayankhattry.ocp1.Calculator (Correct)
  • javac -d out\calc-module src\calculator\module-info.java java --module-path out --module calc-module/com.udayankhattry.ocp1.Calculator

Answer :javac -d out\calc-module src\calculator\com\udayankhattry\ocp1\Calculator.java src\calculator\module-info.java java --module-path out --module calc/com.udayankhattry.ocp1.Calculator


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Line n1 causes compilation error
  • Line n2 causes compilation error
  • false (Correct)
  • true

Answer :false


Consider below code of Guest.java file:



And the commands:

javac Guest.java

java Guest Arya Stark


What is the result?


Options are :

  • An exception is thrown at runtime
  • Message.main(args); causes compilation error in Guest class
  • Welcome! Stark (Correct)
  • Welcome! Arya

Answer :Welcome! Stark


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • ACCESS REQUIRED LEVEL 1 DONE
  • Compilation error
  • ACCESS REQUIRED DONE
  • ACCESS REQUIRED LEVEL 1 (Correct)
  • ACCESS REQUIRED

Answer :ACCESS REQUIRED LEVEL 1


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error in Child interface
  • On execution, Test class prints PLAYING CRICKET... on to the console (Correct)
  • On execution, Test class throws an Exception
  • Compilation error in Test class
  • Compilation error in Parent interface

Answer :On execution, Test class prints PLAYING CRICKET... on to the console


Consider below code of Person.java file:



What will be the result of compiling and executing Person class?


Options are :

  • None of the other options
  • Compilation error
  • null (Correct)
  • James

Answer :null


____________ uses access modifiers to protect variables and hide them within a class.


Which of the following options accurately fill in the blank above?



Options are :

  • Encapsulation (Correct)
  • Abstraction
  • Inheritance
  • Polymorphism

Answer :Encapsulation


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 2
  • 0 (Correct)
  • 1
  • 3

Answer :0


Consider below codes of 2 java files:




What will be the result of compiling and executing Aeroplane class?


Options are :

  • Compilation error at Line n1
  • Given code compiles successfully and on execution prints below in the output: Flying at 20 degrees. Landing at -20 degrees. (Correct)
  • Compilation error at Line n3
  • Compilation error at Line n2

Answer :Given code compiles successfully and on execution prints below in the output: Flying at 20 degrees. Landing at -20 degrees.


Consider below code of Test.java file:



For the class Test, which options, if used to replace /*INSERT*/, will print "SINGAPORE AUSTRALIA CHINA RUSSIA " on to the console?


Options are :

  • for(String [] arr : countries) for(String country : arr) System.out.print(country + " "); (Correct)
  • for(int i = 1; i < countries.length; i++) for(int j = 1; j < countries[i].length ; j++) System.out.print(countries[i][j] + " ");
  • for(int i = 1; i <= countries.length; i++) for(int j = 1; j <= countries[i].length ; j++) System.out.print(countries[i][j] + " ");
  • for(int i = 0; i < countries.length; i++) for(int j = 0; j < countries[i].length ; j++) System.out.print(countries[i][j] + " "); (Correct)

Answer :for(String [] arr : countries) for(String country : arr) System.out.print(country + " "); for(int i = 0; i < countries.length; i++) for(int j = 0; j < countries[i].length ; j++) System.out.print(countries[i][j] + " ");


A module is a set of ____________.


Options are :

  • source code files
  • interfaces
  • classes
  • packages (Correct)

Answer :packages


Consider below code of "01_Msg" file:



And the command:

java --source 11 01_Msg


Following options are available to replace /*INSERT*/:

1. Msg

2. 01_Msg

3. 01Msg

4. Msg01

5. Msg_01

6. Message

7. $msg


How many of the above options can be used to replace /*INSERT*/ (separately and not together) such that given command prints ALL IS WELL on to the console?


Options are :

  • Three options only
  • One option only
  • Five options only (Correct)
  • Six options only
  • Two options only
  • Four options only
  • All seven options

Answer :Five options only


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • END is printed and program terminates successfully
  • Compilation error (Correct)
  • END is printed and program terminates abruptly
  • END is not printed and program terminates abruptly

Answer :Compilation error


Consider below code of Test.java file:



How many String objects are there in the HEAP memory, when control is at Line n9?


Options are :

  • 4
  • 5
  • 2
  • 3 (Correct)

Answer :3


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Program ends abruptly (Correct)
  • Line 12 causes compilation failure
  • Line 7 causes compilation failure
  • SEATS NOT AVAILABLE is printed on to the console and program terminates successfully

Answer :Program ends abruptly


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Java
  • JavaWorld
  • World
  • false (Correct)
  • true

Answer :false


Interface java.util.function.Predicate<T> declares below non-overriding abstract method:

boolean test(T t);


Given code of Test.java file:



Which of the following options can replace /*INSERT*/ such that on executing Test class all the list elements are displayed in the output?

Select ALL that apply.


Options are :

  • p -> true (Correct)
  • p -> p.length() >= 1 (Correct)
  • var p -> p.length() > 0
  • (var p) -> p.length() < 100 (Correct)
  • p -> !!false
  • p -> !!!!true (Correct)
  • p -> p.length() < 7

Answer :p -> true p -> p.length() >= 1 (var p) -> p.length() < 100 p -> !!!!true


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • Prints 5 in an infinite loop
  • 5 3 2 1
  • Prints 5 once (Correct)

Answer :Prints 5 once


Consider below code of main.java file:



Also consider below statements:

1. Code doesn't compile

2. Code compiles successfully

3. Only ONE will be printed to the console

4. Only TWO will be printed to the console

5. Both ONE and TWO will be printed to the console


How many of the above statements is/are true?


Options are :

  • One statement
  • Three statements
  • Two statements (Correct)

Answer :Two statements


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • Result is: false
  • Result is: true (Correct)
  • Result is: (10 != 5)

Answer :Result is: true


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • TWO THREE
  • THREE
  • Compilation error (Correct)
  • None of the System.out.println statements is executed
  • ONE THREE

Answer :Compilation error


Consider below code of Test.java file:



Currently above code causes compilation error.

Which of the option can successfully replace //TODO statement such that on executing Test class, output is 64:TYPE-C?


Options are :

  • super(capacity);
  • this.type = type; super(capacity);
  • super.capacity = capacity; this.type = type;
  • super(capacity); this.type = type; (Correct)

Answer :super(capacity); this.type = type;


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • true true
  • false true
  • true false (Correct)
  • false false
  • Compilation error

Answer :true false


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Program terminates successfully after printing 1231 on to the console (Correct)
  • Program terminates successfully but nothing is printed on to the console
  • Compilation error
  • Program terminates successfully after printing 1 on to the console
  • Program terminates successfully after printing 0120 on to the console
  • Program terminates successfully after printing 123 on to the console
  • Program terminates successfully after printing 121 on to the console
  • Program terminates successfully after printing 12 on to the console

Answer :Program terminates successfully after printing 1231 on to the console


What will be the result of compiling and executing Test class?



Options are :

  • 1
  • Compilation error
  • 2
  • 3 (Correct)

Answer :3


Consider below code of Quotes.java file:



What will be the result of compiling and executing Quotes class?


Options are :

  • NEVER GIVE UP! null
  • null null (Correct)
  • NEVER GIVE UP! NEVER GIVE UP!
  • null NEVER GIVE UP!
  • Compilation error

Answer :null null


What will be the result of compiling and executing Test class?



Options are :

  • 17:35:19:40
  • 17:35:17:40
  • 19:35:19:40 (Correct)
  • 17:40:19:40
  • Compilation error
  • 17:35:19:35

Answer :19:35:19:40


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • Compilation Error in Test class
  • Compilation Error in Sub class (Correct)
  • Compilation Error in Super class
  • It prints OutReach on to the console
  • It prints ReachOut on to the console

Answer :Compilation Error in Sub class


Interface java.util.function.Consumer<T> declares below non-overriding abstract method:

void accept(T t);


Given code of Test.java file:


What will be the result of compiling and executing Test class?


Options are :

  • 100/4 = 25 27/0 = Infinity 25/5 = 5 (Correct)
  • Compilation error
  • On execution Test class throws an exception
  • 100/4 = 25 27/0 = 0 25/5 = 5

Answer :100/4 = 25 27/0 = Infinity 25/5 = 5


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • DATE
  • TO
  • UP-TO
  • Compilation error at Line n1
  • TO-DATE
  • Compilation error at Line n2
  • UP
  • UP-TO-DATE (Correct)

Answer :UP-TO-DATE


Which of the options of java command displays module resolution output?


Options are :

  • --list-module-resolution
  • --list-modules
  • --show-module-resolution (Correct)
  • --display-module-resolution
  • --module-resolution

Answer :--show-module-resolution


Given code:



When is the Pen object, created at Line n1, will be eligible for Garbage Collection?


Options are :

  • After Line n4
  • After Line n3 (Correct)
  • After Line n2
  • At the end of main method

Answer :After Line n3


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • Compilation error in Euro class
  • Compilation error in USDollar class
  • $:$ :
  • -:$ -: (Correct)
  • -:- -:-

Answer :-:$ -:


For the given code:



Which of the following options can replace /*INSERT*/ such that on executing Test class, passed Strings are formatted in Camel case? The output should be:

Hello

Help


Consider that passed string should be continuous, without any white-spaces in between. Select one option from below.


Options are :

  • s -> s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase() (Correct)
  • Other three options are not correct
  • s -> s.toCamelCase()
  • s -> s.substring(0, 1).toUpperCase() + s.substring(1, 5).toLowerCase()

Answer :s -> s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase()


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • true false (Correct)
  • false false
  • false true
  • true true

Answer :true false


Given code of Test.java file:



Which of the following statements is true for above code?


Options are :

  • Compilation error in Test class
  • Code compiles successfully and on execution prints GENERIC on to the console
  • Code compiles successfully and on execution prints RULED on to the console
  • Compilation error in RuledPaper class (Correct)

Answer :Compilation error in RuledPaper class


Which of the following phases of software development are affected by modules?


Options are :

  • Packaging
  • Execution
  • Testing
  • All of the other options (Correct)
  • Coding
  • Compilation

Answer :All of the other options


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • XZ (Correct)
  • XYZ
  • YZ
  • Compilation Error

Answer :XZ


For the given code:



Which of the following statements can be used to replace /*INSERT*/ such that there are no compilation errors?


Options are :

  • Greetings obj = s -> System.out.println(s.toUpperCase());
  • Greetings obj = (String s) -> {System.out.println(s.toUpperCase());};
  • Lambda expression cannot be used in this case (Correct)
  • Greetings obj = s -> {System.out.println(s.toUpperCase());};

Answer :Lambda expression cannot be used in this case


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • You failed...
  • You passed...
  • Compilation error (Correct)
  • Produces no output

Answer :Compilation error


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error in TravelBlogger class
  • TRAVEL is printed on to the console and program terminates successfully (Correct)
  • Compilation error in Test class
  • An exception is thrown at runtime
  • GENERIC is printed on to the console and program terminates successfully

Answer :TRAVEL is printed on to the console and program terminates successfully


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • 5
  • 120.0
  • Compilation error
  • 120 (Correct)
  • 5.0

Answer :120


Consider below 4 code snippets:

1.


2.


3.


4.

System.out.println("4. " + String.join(".", null));


Which of the following statements are correct about above snippets?

Select ALL that apply.


Options are :

  • Snippet 1 throws runtime exception
  • Snippet 3 throws runtime exception (Correct)
  • Snippet 1 compiles successfully (Correct)
  • Snippet 2 throws runtime exception
  • Snippet 4 compiles successfully
  • Snippet 4 throws runtime exception
  • Snippet 3 compiles successfully (Correct)
  • Snippet 2 compiles successfully (Correct)

Answer :Snippet 3 throws runtime exception Snippet 1 compiles successfully Snippet 3 compiles successfully Snippet 2 compiles successfully


Consider the following class:



Which of the following is the correct way to make the variable 'passportNo' read only for any other class?


Options are :

  • Make 'passportNo' static and provide a public static method getPassportNo() which will return its value
  • Remove 'public' from the 'passportNo' declaration. i.e., change line 2 to int passportNo;
  • Make 'passportNo' private
  • Make 'passportNo' private and provide a public method getPassportNo() which will return its value (Correct)

Answer :Make 'passportNo' private and provide a public method getPassportNo() which will return its value


Interface java.util.function.Predicate<T> declares below non-overriding abstract method:

boolean test(T t);


Given code of Test.java file:


What will be the result of compiling and executing Test class?


Options are :

  • A Aa Abab
  • Runtime exception
  • A ab Aa aba Abab (Correct)
  • ab aba
  • Compilation error

Answer :A ab Aa aba Abab


Consider below statements:


1. int x = 5____0;

2. int y = ____50;

3. int z = 50____;

4. float f = 123.76_86f;

5. double d = 1_2_3_4;


How many statements are legal?


Options are :

  • All 5 statements
  • Four statements only
  • Two statements only
  • One statement only
  • Three statements only (Correct)

Answer :Three statements only


Given code of Test.java file:



What is the output if above program is run with the command line:

java Test.java --help


Options are :

  • None of the other options
  • 1 (Correct)
  • 0
  • Above command causes error

Answer :1


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • FINALLY is printed to the console and program ends normally
  • Compilation error
  • FINALLY is printed to the console, stack trace is printed and then program ends normally
  • FINALLY is printed to the console, stack trace is printed and then program ends abruptly (Correct)

Answer :FINALLY is printed to the console, stack trace is printed and then program ends abruptly


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Output string contains @ symbol
  • Compilation error (Correct)
  • TEST
  • Exception is thrown at runtime

Answer :Compilation error


Consider below codes of 3 java files:





Which of the following statements is correct?


Options are :

  • There is no compilation error and on execution, Test class prints 80% on to the console
  • There is a compilation error in AntMan.java file
  • There is a compilation error in Test.java file (Correct)
  • There is a compilation error in Shrinkable.java file

Answer :There is a compilation error in Test.java file


Given code of Test.java file:



Above code causes compilation error, which modifications, done independently, enable the code to compile and on execution print 200 on to the console?

Select ALL that apply.


Options are :

  • Replace /*INSERT*/ with int NUM; (Correct)
  • Replace /*INSERT*/ with short NUM; (Correct)
  • Replace /*INSERT*/ with float NUM;
  • Replace /*INSERT*/ with Object NUM; (Correct)
  • Replace /*INSERT*/ with boolean NUM;
  • Replace /*INSERT*/ with byte NUM;
  • Replace /*INSERT*/ with double NUM;
  • Remove final modifier from Line n1 (Correct)

Answer :Replace /*INSERT*/ with int NUM; Replace /*INSERT*/ with short NUM; Replace /*INSERT*/ with Object NUM; Remove final modifier from Line n1


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error (Correct)
  • [5, 10]
  • [50, 50]
  • An exception is thrown at runtime

Answer :Compilation error


Below is the code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [200, 100, 200]
  • [200]
  • Exception is thrown at runtime (Correct)
  • [100, 200, 200]
  • Compilation error
  • [200, 200]

Answer :Exception is thrown at runtime


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [HeLLo, HeLLo, HeLLo]
  • [HeLLo, Hello, Hello]
  • [HeLLo, Hello, HeLLo]
  • [Hello, Hello, Hello] (Correct)

Answer :[Hello, Hello, Hello]


Given code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • A-B-C-
  • Compilation error in class Test (Correct)
  • Compilation error in class Y
  • AB-C-

Answer :Compilation error in class Test


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 100
  • Line n2 causes compilation error
  • Line n1 causes compilation error (Correct)
  • 10
  • An exception is thrown at runtime

Answer :Line n1 causes compilation error


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • INJURED
  • INJURED DONE
  • INJURED MATCH ABANDONED
  • MATCH ABANDONED DONE
  • INJURED MATCH ABANDONED DONE
  • MATCH ABANDONED
  • Compilation error (Correct)

Answer :Compilation error


_____________ system module defines the foundational APIs of the Java SE Platform.


Options are :

  • jdk.base
  • java
  • java.base (Correct)
  • jdk.se
  • se
  • java.se

Answer :java.base


Consider below codes of 3 java files:





What will be the result of compiling and executing Test class?


Options are :

  • It compiles successfully and on execution prints $35.00 on to the console
  • It compiles successfully and on execution prints 35 on to the console
  • Compilation error in Test class
  • It compiles successfully and on execution prints $35 on to the console
  • It compiles successfully and on execution prints 35.0 on to the console (Correct)
  • Compilation error in Chair class
  • It compiles successfully and on execution prints 35.00 on to the console
  • It compiles successfully and on execution prints $35.0 on to the console

Answer :It compiles successfully and on execution prints 35.0 on to the console


Given code of Test.java file:



Which of the following statements is correct?


Options are :

  • class Test fails to compile
  • class Test compiles successfully and on execution prints X3 on to the console (Correct)
  • interface X3 fails to compile
  • interface X1 fails to compile
  • class X fails to compile
  • class Test compiles successfully and on execution prints X1 on to the console
  • interface X2 fails to compile

Answer :class Test compiles successfully and on execution prints X3 on to the console


Consider below code of Test.java file:



Which of the following statements are correct?

Select ALL that apply.


Options are :

  • Line n1 compiles successfully
  • Line n5 compiles successfully
  • Line n2 compiles successfully
  • Line n4 compiles successfully (Correct)
  • Line n6 compiles successfully (Correct)
  • Line n3 compiles successfully (Correct)

Answer :Line n4 compiles successfully Line n6 compiles successfully Line n3 compiles successfully


Code of Test.java file below:


What will be the result of compiling and executing Test class using below commands:

javac Test.java

java Test laugh out loud


Options are :

  • out
  • loud
  • laugh
  • Compilation Error (Correct)

Answer :Compilation Error


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Line n1 causes compilation error (Correct)
  • 0.0
  • Line n2 causes runtime exception
  • 0

Answer :Line n1 causes compilation error


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Program ends abruptly (Correct)
  • Line 10 causes compilation failure
  • REPORT ERROR is printed on to the console and program terminates successfully
  • Line 16 causes compilation failure

Answer :Program ends abruptly


Which of the following can be used as a constructor for the class given below?


Options are :

  • public void Planet(int x){}
  • public void Planet(){}
  • public Planet(String str) {} (Correct)
  • None of the other options

Answer :public Planet(String str) {}


Interface java.util.function.Predicate<T> declares below non-overriding abstract method:

boolean test(T t);


Given code of Test.java file:


What will be the result of compiling and executing Test class?


Options are :

  • * ** ***
  • * ** *** **** *****
  • Compilation error (Correct)
  • * ** *** ****

Answer :Compilation error


Consider below interface:



Which of the following is the correct lambda expression for ICalculator?


Options are :

  • ICalculator obj2 = (x) -> return x*x;
  • ICalculator obj4 = x -> x*x; (Correct)
  • ICalculator obj1 = x -> return x*x;
  • ICalculator obj3 = x - > x*x;

Answer :ICalculator obj4 = x -> x*x;


Given code of TestRectangle.java file:



What will be the result of compiling and executing above code?


Options are :

  • 200, 100
  • Compilation Error (Correct)
  • 100, 200
  • 0, 0

Answer :Compilation Error


In a modular application, is it possible to have empty module-info.java file?


Options are :

  • No (Correct)
  • Yes

Answer :No


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • 11 : h
  • Compilation error
  • 10 : !
  • 11 : ! (Correct)
  • 10 : h

Answer :11 : !


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Person[Liam, 27]
  • Person[Liam, 25] Person[Liam, 27] Person[Liam, 25] Person[Liam, 25] (Correct)
  • Person[Liam, 25] Person[Liam, 27] Person[Liam, 25]
  • Person[Liam, 27] Person[Liam, 25] Person[Liam, 25]

Answer :Person[Liam, 25] Person[Liam, 27] Person[Liam, 25] Person[Liam, 25]


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • 10
  • Exception is thrown at runtime
  • 11 (Correct)

Answer :11


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • 89
  • An exception is thrown at runtime
  • 01234567 (Correct)

Answer :01234567


Given below the directory/file structure on Windows platform:


Below is the code of Test.java file:


And below is the code of module-info.java file:


And below commands:

C:\>javac --module-source-path src -d out --module com.messages


C:\>java -p out -m com.messages/com.messages.Test


Which of the following options replaces <MODULE_DIRECTORY_NAME> such that output of the 2nd command is: COMMIT OR QUIT?


Options are :

  • com.messages (Correct)
  • mymodule
  • messages
  • messages-module
  • com.messages-module
  • com.messages.module

Answer :com.messages


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 7
  • 3
  • Compilation error
  • 6
  • 8
  • An exception is thrown at runtime
  • 9 (Correct)

Answer :9


Given code of Test.java file:



And the command:

java Test.java


What is the result?


Options are :

  • INHALE-EXHALE-EXHALE
  • INHALE-EXHALE-
  • INHALE-EXHALE-INHALE-EXHALE (Correct)
  • INHALE-EXHALE
  • INHALE-EXHALE-INHALE-

Answer :INHALE-EXHALE-INHALE-EXHALE


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • PANIC
  • PATHETIC (Correct)
  • Line n1 throws error at runtime
  • Line n1 causes compilation error

Answer :PATHETIC


Consider below code of Test.java file:



And the commands:

javac Test.java

java Test "James Gosling" "Bill Joy"


What is the result?


Options are :

  • Welcome "James Gosling!"
  • Welcome Gosling
  • Welcome Bill Joy
  • Welcome "Bill Joy"
  • Welcome James
  • Welcome Joy
  • Welcome Bill
  • Welcome James Gosling! (Correct)

Answer :Welcome James Gosling!


Given code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error in both Super and Sub classes
  • Compilation error only in Super class
  • Test class executes successfully and prints CARPE DIEM on to the console (Correct)
  • Test class executes successfully and prints DIEM CARPE on to the console
  • Compilation error only in Sub class

Answer :Test class executes successfully and prints CARPE DIEM on to the console


Given below the directory/file structure on Windows platform:


Contents of C:\src\holidays\module-info.java file:


And the command executed from C:\

javac -d out --module-source-path src -m holidays


What is the result?


Options are :

  • javac command completes without any warning (Correct)
  • javac command fails as there are no source code files other than module-info.java
  • javac command fails as module-info.java file is not valid
  • javac command completes with warning

Answer :javac command completes without any warning


Consider below code of Test.java file:



What will be the result of compiling and executing above code?


Options are :

  • Compilation error in Car class
  • 1
  • An exception is thrown at runtime
  • Compilation error in Test class (Correct)
  • 2
  • Compilation error in Vehicle class

Answer :Compilation error in Test class


For the class Test, which options, if used to replace /*INSERT*/, will print "Lucky no. 7" on to the console?

Select ALL that apply.



Options are :

  • Character var = 7; (Correct)
  • char var = 7; (Correct)
  • Character var = '7';
  • Integer var = 7; (Correct)
  • char var = '7';

Answer :Character var = 7; char var = 7; Integer var = 7;


Below is the code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • Compilation error at Line n1
  • 42
  • Compilation error at Line n3 (Correct)
  • Compilation error at Line n2

Answer :Compilation error at Line n3


Which of the following options correctly import the Panda class from com.singaporezoo.animal package?

Select 2 options.


Options are :

  • import com.singaporezoo.animal.Panda; (Correct)
  • import com.singaporezoo.animal.*; (Correct)
  • Import com.singaporezoo.animal.Panda;
  • import com.singaporezoo.animal;
  • import com.singaporezoo.*;

Answer :import com.singaporezoo.animal.Panda; import com.singaporezoo.animal.*;


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • [MOVE, null, ON, null]
  • An exception is thrown at runtime (Correct)
  • [MOVE, ON]
  • [null, null, null, null]
  • Compilation error
  • []

Answer :An exception is thrown at runtime


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • BABA (Correct)
  • BAB
  • ABBA
  • BA
  • ABA
  • ABAB
  • AB
  • Compilation error at Line n2
  • B

Answer :BABA


Consider below code of Test.java file:



Which of the following options, if used to replace /*INSERT*/, will compile successfully and on execution will print THINK DIFFERENT on to the console?


Options are :

  • break var; (Correct)
  • break i;
  • break;
  • continue i;
  • continue;
  • continue var;

Answer :break var;


Consider below code of Test.java file:



Line n1 causes compilation error as subtext method is not found.

Which of the following method definitions, if used to replace /*INSERT*/, will resolve the compilation error?

Select ALL that apply.


Options are :

  • private static String subtext(String text, int start, int end) { return null; } (Correct)
  • private static int[] subtext(String text, int start, int end) { return null; } (Correct)
  • private static int subtext(String text, int start, int end) { return null; }
  • private static var subtext(String text, int start, int end) { return null; }
  • private static String subtext(var text, int start, int end) { return null; }
  • private static String[] subtext(String text, int start, int end) { return null; } (Correct)

Answer :private static String subtext(String text, int start, int end) { return null; } private static int[] subtext(String text, int start, int end) { return null; } private static String[] subtext(String text, int start, int end) { return null; }


Given below the directory/file structure on Windows platform:


Please note directory 'planet' contains Earth.java file, directory 'satellite' is empty and there is no 'artificial' directory under 'satellite' directory.


Contents of C:\src\solarsystem\com\planet\Earth.java file:


Contents of C:\src\solarsystem\module-info.java file:


And below javac command is executed from C:\

javac -d out --module-source-path src -m solarsystem


What is the result?


Options are :

  • Code compiles but with a warning for both Line n2 and Line n3
  • Code compiles but with a warning for Line n2 only
  • Code compiles without any warning
  • Compilation error for both Line n2 and Line n3 (Correct)
  • Code compiles but with a warning for Line n3 only
  • Compilation error for Line n3 only
  • Compilation error for Line n2 only

Answer :Compilation error for both Line n2 and Line n3


What will be the result of compiling and executing Test class?



Options are :

  • Compilation error (Correct)
  • Not a valid score Failed
  • Failed
  • Passed

Answer :Compilation error


Consider below code of Test.java file:



What will be the result of compiling and executing Test class?


Options are :

  • 1 2
  • 1 3 4 5 6 7
  • 1 2 3 4 5 6 7
  • An exception is thrown at runtime
  • Compilation fails
  • 1 3
  • 1 2 4 5 6 7 (Correct)

Answer :1 2 4 5 6 7


Consider below code of "Util.txt" file:



And the command:

java --source 11 Util.txt 10 20


What is the result?


Options are :

  • 30
  • 2010
  • 1020 (Correct)
  • Above command causes error

Answer :1020


Consider below code of Test.java file:



Which of the following statements is correct?


Options are :

  • No compilation error
  • Two statements cause compilation error
  • Three statements cause compilation error
  • Only one statement causes compilation error (Correct)
  • Four statements cause compilation error

Answer :Only one statement causes compilation error


Consider below codes of 3 java files: