Java MCQ Quiz 1
Java MCQ Quiz 1
Java
Q1. Given the string "strawberries" saved in a variable called fruit, what would
fruit.substring(2, 5) return?
rawb
raw
awb
traw
method overloading
method overrunning
method overriding
method calling
Q3. Given the following definitions, which of these expression will NOT evaluate to
true?
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 1/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
(i1 | i2) == 3
i2 && b1
b1 || !b2
1: class Main {
2: public static void main (String[] args) {
3: int array[] = {1, 2, 3, 4};
4: for (int i = 0; i < array.size(); i++) {
5: System.out.print(array[i]);
6: }
7: }
8: }
Reasoning: array.size() is invalid, to get size or length of array array.length can be used.
Q5. Which of the following can replace the CODE SNIPPET to make the code below
print "Hello World"?
interface Interface1 {
static void print() {
System.out.print("Hello");
}
}
interface Interface2 {
static void print() {
System.out.print("World!");
}
}
super1.print(); super2.print();
this.print();
super.print();
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 2/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Interface1.print(); Interface2.print();
Reference
CD
CDE
D
"abcde"
Reasoning: You should assign the result of trim back to the String variable. Otherwise, it
is not going to work, because strings in Java are immutable.
class Main {
public static void main (String[] args){
System.out.println(print(1));
}
static Exception print(int i){
if (i>0) {
return new Exception();
} else {
throw new RuntimeException();
}
}
}
interface One {
default void method() {
System.out.println("One");
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 3/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
}
}
interface Two {
default void method () {
System.out.println("One");
}
}
class Main {
public static void main (String[] args) {
List list = new ArrayList();
list.add("hello");
list.add(2);
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 4/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Q10. Given the following two classes, what will be the output of the Main class?
package mypackage;
public class Math {
public static int abs(int num){
return num < 0 ? -num : num;
}
}
package mypackage.elementary;
public class Math {
public static int abs (int num) {
return -num;
}
}
import mypackage.Math;
import mypackage.elementary.*;
class Main {
public static void main (String args[]){
System.out.println(Math.abs(123));
}
}
Explanation: The answer is "123". The abs() method evaluates to the one inside
mypackage.Math class, because the import statements of the form:
import packageName.subPackage.*
1: class MainClass {
2: final String message() {
3: return "Hello!";
4: }
5: }
class Main {
public static void main(String[] args) {
System.out.println(args[2]);
}
}
class Main {
public static void main(String[] args){
int a = 123451234512345;
System.out.println(a);
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 6/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
}
}
"123451234512345"
Nothing - this will not compile.
a negative integer value
"12345100000"
Reasoning: The int type in Java can be used to represent any whole number from
-2147483648 to 2147483647. Therefore, this code will not compile as the number
assigned to 'a' is larger than the int type can hold.
class Main {
public static void main (String[] args) {
String message = "Hello world!";
String newMessage = message.substring(6, 12)
+ message.substring(12, 6);
System.out.println(newMessage);
}
}
Q15. How do you write a foreach loop that will iterate over
ArrayList<Pencil>pencilCase?
for (pencilCase.next()) {}
System.out.print("apple".compareTo("banana"));
positive number
negative number
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 7/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
compilation error
Q17. You have an ArrayList of names that you want to sort alphabetically. Which
approach would NOT work?
names.sort(Comparator.comparing(String::toString))
Collections.sort(names)
names.sort(List.DESCENDING)
Reference
private
protected
no-modifier
public
Q19. Which is the most up-to-date way to instantiate the current date?
new Date(System.currentTimeMillis())
LocalDate.now()
Calendar.getInstance().getTime()
Q20. Fill in the blank to create a piece of code that will tell whether int0 is divisible
by 5 :
int0 % 5 == 0
int0 % 5 != 5
Math.isDivisible(int0, 5)
Q21. How many times will this code print "Hello World!"?
class Main {
public static void main(String[] args){
for (int i=0; i<10; i=i++){
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 8/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
i+=1;
System.out.println("Hello World!");
}
}
}
10 times
9 times
5 times
infinite number of times
Q22. The runtime system starts your program by calling which function first?
print
iterative
hello
main
/* Constructor B */
Jedi(String name, String species, boolean followsTheDarkSide){}
}
Reference
Q24. "An anonymous class require a zero-argument constructor." that's not true?
An anonymous class may specify an abstract base class as its base type.
An anonymous class does not require a zero-argument constructor.
An anonymous class may specify an interface as its base type.
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 9/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
An anonymous class may specify both an abstract class and interface as base types.
Q25. What will this program print out to the console when executed?
import java.util.LinkedList;
[5, 1, 10]
[10, 5, 1]
[1, 5, 10]
[10, 1, 5]
class Main {
public static void main(String[] args){
String message = "Hello";
for (int i = 0; i<message.length(); i++){
System.out.print(message.charAt(i+1));
}
}
}
"Hello"
A runtime exception is thrown.
The code does not compile.
"ello"
functions; actions
objects; actions
actions; functions
actions; objects
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 10/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
"nifty".getType().equals("String")
"nifty".getType() == String
"nifty".getClass().getSimpleName() == "String"
import java.util.*;
class Main {
public static void main(String[] args) {
List<Boolean> list = new ArrayList<>();
list.add(true);
list.add(Boolean.parseBoolean("FalSe"));
list.add(Boolean.TRUE);
System.out.print(list.size());
System.out.print(list.get(1) instanceof Boolean);
}
}
1: class Main {
2: Object message() {
3: return "Hello!";
4: }
5: public static void main(String[] args) {
6: System.out.print(new Main().message());
7: System.out.print(new Main2().message());
8: }
9: }
10: class Main2 extends Main {
11: String message() {
12: return "World!";
13: }
14: }
another instance
field
constructor
private method
Q32. Which is the most reliable expression for testing whether the values of two
string variables are the same?
string1 == string2
string1 = string2
string1.matches(string2)
string1.equals(string2)
A, B, and D
A, C, and D
C and D
A and D
class Main {
static int count = 0;
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 12/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
import java.util.*;
class Main {
public static void main(String[] args) {
String[] array = {"abc", "2", "10", "0"};
List<String> list = Arrays.asList(array);
Collections.sort(list);
System.out.println(Arrays.toString(array));
}
}
[abc, 0, 2, 10]
class Main {
public static void main(String[] args) {
String message = "Hello";
print(message);
message += "World!";
print(message);
}
static void print(String message) {
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 13/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
System.out.print(message);
message += " ";
}
}
Hello World!
HelloHelloWorld!
Hello Hello World!
Hello HelloWorld!
x
null
10
5
Q38. Which approach cannot be used to iterate over a List named theList?
Iterator it = theList.iterator();
for (it.hasNext()) {
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 14/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
System.out.println(it.next());
}
theList.forEach(System.out::println);
provides, employs
imports, exports
consumes, supplies
requires, exports
non-static
static
final
private
Q42. How does the keyword volatile affect how a variable is handled?
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 15/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
System.out.println((int) smooch);
an alphanumeric character
a negative number
a positive number
a ClassCastException
ducks.add(new Duck("Waddles"));
ducks.add(new Waddles());
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 16/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
executed; interpreting
executed; compiling
compiled; executing
compiled, translating
Q48. Given this class, how would you make the code compile?
public TheClass() {
x += 77;
}
public TheClass() {
x = null;
}
public TheClass() {
x = 77;
}
Explanation: final class members are allowed to be assigned only in three places:
declaration, constructor or an instance-initializer block.
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 17/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
4
3
5
A Runtime exception will be thrown
1, 2, and 3
only 3
2 and 3
only 2
Q51. Which keyword lets you call the constructor of a parent class?
parent
super
this
new
1: int a = 1;
2: int b = 0;
3: int c = a/b;
4: System.out.println(c);
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 18/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Q53. Normally, to access a static member of a class such as Math.PI, you would need
to specify the class "Math". What would be the best way to allow you to use simply
"PI" in your code?
extends
implements
inherits
import
You don't have to decide the size of an ArrayList when you first make it.
You can put more items into an ArrayList than into an array.
ArrayLists can hold more kinds of objects than arrays.
You don't have to decide the type of an ArrayList when you first make it.
int pi = 3.141;
decimal pi = 3.141;
double pi = 3.141;
float pi = 3.141;
Reasoning:
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 19/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
The default Java type which Java will be using for a float variable will
be double.
So, even if you declare any variable as float, what the compiler has to
actually do is to assign a double value to a float variable,
which is not possible. So, to tell the compiler to treat this value as a
float, that 'F' is used.
MagicPower.castSpell("expelliarmus");
new MagicPower.castSpell();
Reference
constructor
instance
class
method
10 10
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 20/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
5 10
10 5
55
try {
System.out.println("Hello World");
} catch (Exception e) {
System.out.println("e");
} catch (ArithmeticException e) {
System.out.println("e");
} finally {
System.out.println("!");
}
Hello World
It will not compile because the second catch statement is unreachable
Hello World!
It will throw runtime exception
finally
native
interface
unsigned
Q62. Which operator would you use to find the remainder after division?
//
DIV
Reference
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 21/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Reference
groucyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Press me one more time..");
}
});
Reference
Q66. Which functional interfaces does Java provide to serve as data types for lambda
expressions?
Observer, Observable
Collector, Builder
Filter, Map, Reduce
Consumer, Predicate, Supplier
Reference
Reference
uses-a
is-a
has-a
was-a
Reference
Reference
Q70. Java programmers commonly use design patterns. Some examples are the _,
which helps create instances of a class, the _, which ensures that only one instance of
a class can be created; and the _, which allows for a group of algorithms to be
interchangeable.
Q71. Using Java's Reflection API, you can use _ to get the name of a class and _ to
retrieve an array of its methods.
this.getClass().getSimpleName(); this.getClass().getDeclaredMethods()
this.getName(); this.getMethods()
Reflection.getName(this); Reflection.getMethods(this)
Reflection.getClass(this).getName(); Reflection.getClass(this).getMethods()
a -> false;
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 23/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Q73. Which access modifier makes variables and methods visible only in the class
where they are declared?
public
protected
nonmodifier
private
private
non-static
final
static
"21".intValue()
String.toInt("21")
Integer.parseInt("21")
String.valueOf("21")
Q76. What method should be added to the Duck class to print the name Moby?
Duck(String name) {
this.name = name;
}
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 24/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
&
Reference
two
four
three
five
p
r
e
i
Q81. What phrase indicates that a function receives a copy of each argument passed
to it rather than a reference to the objects themselves?
pass by reference
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 25/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
pass by occurrence
pass by value
API call
5
8
1
3
Explanation: Changing line 2 to public static final String message raises the error
message not initialized in the default constructor .
import java.util.*;
class Main {
public static void main(String[] args) {
String[] array = new String[]{"A", "B", "C"};
List<String> list1 = Arrays.asList(array);
List<String> list2 = new ArrayList<>(Arrays.asList(array));
List<String> list3 = new ArrayList<>(Arrays.asList("A", new String("B")
System.out.print(list1.equals(list2));
System.out.print(list1.equals(list3));
}
}
falsefalse
truetrue
falsetrue
truefalse
class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("hello");
sb.deleteCharAt(0).insert(0, "H")." World!";
System.out.println(sb);
}
}
Q88. How would you use the TaxCalculator to determine the amount of tax on $50?
class TaxCalculator {
static calculate(total) {
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 27/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
TaxCalculator.calculate(50);
new TaxCalculator.calculate(50);
calculate(50);
new TaxCalculator.calculate($50);
1. Reference
2. Code sample
Reference
import java.util.*;
1324
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 28/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
4231
1234
4321
Q91. What will this code print, assuming it is inside the main method of a class?
my
hellomyfriends
hello
friends
2
When calling the put method, Java will throw an exception
4
3
Q93. Which class acts as root class for Java Exception hierarchy?
Clonable
Throwable
Object
Serializable
java.util.Vector
java.util.ArrayList
java.util.HashSet
java.util.HashMap
employees.filter(Employee::getName).collect(Collectors.toUnmodifiableList());
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 29/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
employees.stream().map(Employee::getName).collect(Collectors.toList());
Q96. This code does not compile. What needs to be changed so that it does?
Add a constructor that accepts a String parameter and assigns it to the field
shortCode .
try-catch-finally
try-finally-close
try-with-resources
try-catch-close
1: class Main {
2: public static void main(String[] args) {
3:
4: array[0] = new int[]{1, 2, 3};
5: array[1] = new int[]{4, 5, 6};
6: array[2] = new int[]{7, 8, 9};
7: for (int i = 0; i < 3; i++)
8: System.out.print(array[i][1]); //prints 258
9: }
10: }
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 30/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
class Car {
public void accelerate() {}
}
class Lambo extends Car {
public void accelerate(int speedLimit) {}
public void accelerate() {}
}
neither
both
overloading
overriding
Q100. Which choice is the best data type for working with money in Java?
float
String
double
BigDecimal
Reference
Regular Expressions
Reflection
Generics
Concurrency
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 31/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
raspberry
strawberry
blueberry
rasp
forestSpecies.put("Amazon", 30000);
forestSpecies.put("Congo", 10000);
forestSpecies.put("Daintree", 15000);
forestSpecies.put("Amazon", 40000);
3
4
2
When calling the put method, Java will throw an exception
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Main {
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 32/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
interface MyInterface {
int foo(int x);
}
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 33/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
interface Foo {
int x = 10;
}
10
20
null
An error will occur when compiling.
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 34/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Q109. Which statement must be inserted on line 1 to print the value true?
1:
2: Optional<String> opt = Optional.of(val);
3: System.out.println(opt.isPresent());
Q110. What will this code print, assuming it is inside the main method of a class?
false
true
true
true
true
false
false
false
list1.remove(list2);
System.out.println(list1);
[Two]
[One, Three]
Two
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 35/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Q112. Which code checks whether the characters in two Strings,named time and
money , are the same?
if(time.equals(money)){}
if(time == money){}
if(time = money){}
Q113. An _ is a serious issue thrown by the JVM that the JVM is unlikely to recover
from. An _ is an unexpected event that an application may be able to deal with in
order to continue execution.
exception,assertion
AbnormalException, AccidentalException
error, exception
exception, error
class Unicorn {
_____ Unicorn(){}
}
static
protected
public
void
List[] myLists = {
new ArrayList<>(),
new LinkedList<>(),
new Stack<>(),
new Vector<>(),
};
composition
generics
polymorphism
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 36/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
encapsulation
String a = "bikini";
String b = new String("bikini");
String c = new String("bikini");
System.out.println(a == b);
System.out.println(b == c);
true; false
false; false
false; true
true; true
Q117. What keyword is added to a method declaration to ensure that two threads do
not simultaneously execute it on the same object instance?
native
volatile
synchronized
lock
Reference
Function<Integer, Boolean>
Function<String>
Function<Integer, String>
Function<Integer>
Explaination, Reference
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 37/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
import java.util.HashMap;
pantry.put("Apples", 3);
pantry.put("Oranges", 2);
System.out.println(pantry.get("Apples"));
}
}
6
3
4
7
Explanation
Function<String, String>
Stream<String>
String<String, String>
Map<String, String>
Explanation, Reference
Q121. Which is the correct return type for the processFunction method?
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 38/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Integer
String
Consumer
Function<Integer, String>
Explanation
Q122. What function could you use to replace slashes for dashes in a list of dates?
Explanation: replaceAll method for any List only accepts UnaryOperator to pass every
single element into it then put the result into the List again.
Object
Main
Java
Class
Explanation
Q124. How do you create and run a Thread for this class?
import java.util.date;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 39/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
}
}
}
new CurrentDateRunnable().run();
new CurrentDateRunnable().start();
Reference
.mapToInt(x -> x * x)
.sum();
Explanation: The given code in the question will give you the output 20 as total:
print
out
err
in
Q127. The compiler is complaining about this assignment of the variable pickle to the
variable jar. How woulld you fix this?
double pickle = 2;
int jar = pickle;
Reference
Q128. What value should x have to make this loop execute 10 times?
10
3
1
0
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 41/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Q129. The _ runs compiled Java code, while the _ compiles Java files.
IDE; JRE
JDK; IDE
JRE; JDK
JDK; JRE
Reference
java.net
java.util
java.lang
All above
Reference
Q131. What values for x and y will cause this code to print "btc"?
int x = 0; int y = 2;
int x = 1; int y = 3;
int x = 0; int y = 3;
int x = 1; int y = 3;
Q132. Which keyword would you add to make this method the entry point of the
program?
exception
args
static
String
Reference
Q133. You have a list of Bunny objects that you want to sort by weight using
Collections.sort. What modification would you make to the Bunny class?
Reference
Object oriented
Use of pointers
Dynamic
Architectural neural
Reference
int yearsMarried = 2;
switch (yearsMarried) {
case 1:
System.out.println("paper");
case 2:
System.out.println("cotton");
case 3:
System.out.println("leather");
default:
System.out.println("I don't gotta buy gifts for nobody!");
}
cotton
cotton
leather
cotton
leather
I don't gotta buy gifts for nobody!
cotton
I don't gotta buy gifts for nobody!
Reference
System.out::println
Doggie::fetch
condensed invocation
static references
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 43/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
method references
bad code
Reference
Q137. What is the difference between the wait() and sleep methods?
Only Threads can wait, but any Object can be put to sleep.
A wait can be woken up by another Thread calling notify whereas a sleep cannot.
When things go wrong, sleep throws an IllegalMonitorStateException whereas wait
throws an InterruptedException.
Sleep allows for multi-threading whereas wait does not.
Reference
Q140. Which data structure would you choose to associate the amount of rainfall
with each month?
Vector
LinkedList
Map
Queue
Explanation:
Map because map is a key/value pair without creating new classes/objects. So can store
the rainfall per month like Map<java.time.Month, Double> . The other options will most
likely need some new class to be meaningful:
java.sql timestamp
java.io time
java.io.timestamp
java.sql.time
32 and 64
32 and 32
64 and 64
64 and 32
Q143. When you pass an object reference as an argument to a method call what gets
passed?
a reference to a copy
a copy of the reference
the object itself
the original reference
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 45/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
User thread
Daemon thread
Both
None of these
JVM invokes the thread's run() method when the thread is initially executed.
Main application running the thread.
start() method of the thread class.
None of the above.
Explanation: After a thread is started, via its start() method of the Thread class, the
JVM invokes the thread's run() method when the thread is initially executed.
Explanation: Final classes are created so the methods implemented by that class cannot
be overridden. It can't be inherited. These classes are declared final .
Q150. Which method can be used to find the highest value of x and y?
Math.largest(x,y)
Math.maxNum(x,y)
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 46/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
Math.max(x,y)
Math.maximum(x,y)
Consumer
Producer
Both
None
Predicate
Interface
Class
Methods
Class
Interface
Predicate
Function
1: class Main {
7: int result = 0;
8:
9: result += entry.getValue();
10: }
class Car {
String color = "blue";
}
public Lambo() {
System.out.println(super.color);
System.out.println(this.color);
System.out.println(color);
}
}
0
0.0
null
undefined
class variable_scope {
public static void main(String args[]) {
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 48/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
int x;
x = 5;
{
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}
}
Compilation Error
Runtime Error
5656
565
extends
abstracts
interfaces
implements
Reference
import java.util.Formatter;
public class Course {
public static void main(String[] args) {
Formatter data = new Formatter();
data.format("course %s", "java ");
System.out.println(data);
data.format("tutorial %s", "Merit campus");
System.out.println(data);
}
}
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 49/50
9/6/23, 9:55 PM linkedin-skill-assessments-quizzes/java/java-quiz.md at main · Ebazhanov/linkedin-skill-assessments-quizzes · GitHub
O(N*N)
O(1)
O(AB)
O(A*B)
1. false 2. true
1. false 2. false
1. true 2. false
1. true 2. true
https://github.com/Ebazhanov/linkedin-skill-assessments-quizzes/blob/main/java/java-quiz.md 50/50