LinkedIn Java Skill Assessment Answers 2022
3 min readOct 19, 2022
Q1. Given the string “strawberries” saved in a variable called fruit, what would fruit.substring(2, 5)
return?
- rawb
- raw
- awb
- traw
Reasoning: The substring method is accepting two arguments.
- The first argument being the index to start(includes that char at 2)
- and the second the index of the string to end the substring(excludes the char at 5).
- Strings in Java are like arrays of chars.
- Therefore, the method will return “raw” as those are the chars in indexes 2,3, and 4.
- You can also take the ending index and subtract the beginning index from it, to determine how many chars will be included in the substring (5–2=3).
Q2. How can you achieve runtime polymorphism in Java?
- method overloading
- method overrunning
- method overriding
- method calling
Q3. Given the following definitions, which of these expression will NOT evaluate to true?
boolean b1 = true, b2 = false; int i1 = 1, i2 = 2;
(i1 | i2) == 3
i2 && b1
b1 || !b2
(i1 ^ i2) < 4
Q4. What is the output of this code?
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: }
- It will not compile because of line 4.
- It will not compile because of line 3.
- 123
- 1234
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();
Interface1.print(); Interface2.print();
Q6. What does the following code print?
String str = "abcde";
str.trim();
str.toUpperCase();
str.substring(3, 4);
System.out.println(str);
- CD
- CDE
- D
- “abcde”
Q7. What is the result of this code?
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();
}
}
}
- It will show a stack trace with a runtime exception.
- “java.lang.Exception”
- It will run and throw an exception.
- It will not compile.
Q8. Which class can compile given these declarations?
interface One {
default void method() {
System.out.println("One");
}
}
interface Two {
default void method () {
System.out.println("One");
}
}
- A
class Three implements One, Two {
public void method() {
super.One.method();
}
}
- B
class Three implements One, Two {
public void method() {
One.method();
}
}
- C
class Three implements One, Two {
}
- D
class Three implements One, Two {
public void method() {
One.super.method();
}
}
Q9. What is the output of this code?
class Main {
public static void main (String[] args) {
List list = new ArrayList();
list.add("hello");
list.add(2);
System.out.print(list.get(0) instanceof Object);
System.out.print(list.get(1) instanceof Integer);
}
}
- The code does not compile.
- truefalse
- truetrue
- falsetrue
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));
}
}
- Lines 1 and 2 generate compiler errors due to class name conflicts.
- “-123”
- It will throw an exception on line 5.
- “123”
for more question and answers please visit: