Home > Java Programming > Quizzes > Java Programming Quiz
Java Programming Quiz
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 18% Most missed: “What keyword is added to a method declaration to ensure that two threads do not …”

Java programming MCQs For LinkedIn Skill Assessments.

Java Programming Quiz
Time left 00:00
25 Questions

1. Given this code, which command will output '2'?
java
class Main {
public static void main(String[] args) {
System.out.println(args[2]);
}
}
2. 'Note:' This code won't compile, possibly broken code sample.
24. Which statement is 'NOT' true?
3. What will this program print out to the console when executed?
java
import java.util.LinkedList;
public class Main {
public static void main(String[] args){
LinkedList list = new LinkedList<>();
list.add(5);
list.add(1);
list.add(10);
System.out.println(list);
}
}
4. What is the result of this code?
java
try {
System.out.println('Hello World');
} catch (Exception e) {
System.out.println('e');
} catch (ArithmeticException e) {
System.out.println('e');
} finally {
System.out.println('!');
}
5. How do you write a foreach loop that will iterate over ArrayList\pencilCase?
6. Which type of variable keeps a constant value once it is assigned?
7. Which keyword lets you use an interface?
8. Refactor this event handler to a lambda expression:
java
groucyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println('Press me one more time..');
}
});
9. What is the result of this code?
java
1: int a = 1;
2: int b = 0;
3: int c = a/b;
4: System.out.println(c);
10. Which keyword lets you call the constructor of a parent class?
11. What is the output of this code?
java
class Main {
static int count = 0;
public static void main(String[] args) {
if (count < 3) {
count++;
main(null);
} else {
return;
}
System.out.println('Hello World!');
}
}
12. What is the output of this code?
java
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: }
13. Which choice is a disadvantage of inheritance?
14. You have a variable of named 'employees' of type 'List' containing multiple entries. The 'Employee' type has a method 'getName()' that returns te employee name. Which statement properly extracts a list of employee names?
15. What code should go in line 3?
java
class Main {
public static void main(String[] args) {
array[0] = new int[]{1, 2, 3};
array[1] = new int[]{4, 5, 6};
array[2] = new int[]{7, 8, 9};
for (int i = 0; i < 3; i++)
System.out.print(array[i][1]); //prints 258
}
}
16. The runtime system starts your program by calling which function first?
17. What is the result of this code?
java
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: }
18. What is a problem with this code?
java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Main {
public static void main( String[] args ) {
List list = new ArrayList( Arrays.asList( 'a', 'b', 'c' ) );
for( String value :list ){
if( value.equals( 'a' ) ) {
list.remove( value );
}
}
System.out.println(list); // outputs [b,c]
}
}
19. Which is the most up-to-date way to instantiate the current date?
20. You get a NullPointerException. What is the most likely cause?
21. What is the output of this code?
java
import java.util.*;
class Main {
public static void main(String[] args) {
String[] array = new String[]{'A', 'B', 'C'};
List list1 = Arrays.asList(array);
List list2 = new ArrayList<>(Arrays.asList(array));
List list3 = new ArrayList<>(Arrays.asList('A', new String('B'), 'C'));
System.out.print(list1.equals(list2));
System.out.print(list1.equals(list3));
}
}
22. What will this code print, assuming it is inside the main method of a class?
java
System.out.println(true && false || true);
System.out.println(false || false && true);
23. Which statement about constructors is not ture?
24. Use the magic power to cast a spell
java
public class MagicPower {
void castSpell(String spell) {}
}
25. What is the output of this code?
java
public class Main {
public static void main (String[] args) {
int[] sampleNumbers = {8, 5, 3, 1};
System.out.println(sampleNumbers[2]);
}
}