Java Quiz Java Quiz 1 / 20What is the main method signature in Java? public static void main(String[] args) public void main(String[] args) public static int main(String[] args) public void main() 2 / 20Which of the following is not a primitive data type in Java? int float String char 3 / 20What is the size of an int variable in Java? 4 bytes 8 bytes 2 bytes 1 byte 4 / 20Which keyword is used to create a subclass in Java? extends implements inherits subclass 5 / 20What is the output of the following code?int x = 5;System.out.println(++x);click on Extem for view full code 5 6 4 7 6 / 20Which method is used to compare two strings for equality in Java? equals() compareTo() == isEqual() 7 / 20Which of these is a checked exception? NullPointerException ArrayIndexOutOfBoundsException FileNotFoundException ArithmeticException 8 / 20What is the purpose of the final keyword in Java? To declare a constant To prevent method overriding To prevent inheritance All of the above 9 / 20How do you declare an array in Java? int[] arr = new int[5]; int arr[] = new int[5]; int arr[5] = new int[]; Both A and B 10 / 20What is the output of the following code?String str = "Hello";str.concat(" World");System.out.println(str);click on Extem for view full code Hello Hello World World HelloWorld 11 / 20What is the difference between StringBuilder and StringBuffer in Java? "StringBuilder" is thread-safe "StringBuffer" is thread-safe Both are thread-safe Neither are thread-safe 12 / 20Which of these statements is correct about Java 8 Stream API? Streams are iterators Streams are reusable Streams support parallel operations Streams can be consumed multiple times 13 / 20What is the use of the Optional class in Java? To handle null pointer exceptions To create optional methods To avoid explicit null checks Both A and C 14 / 20How do you make a class immutable in Java? Declare the class as 'final' Make all fields private and final Provide only getters All of the above 15 / 20What is the output of the following code?int a = 10;int b = 20;int c = 30;a = b = c;System.out.println(a + " " + b + " " + c);click on Extem for view full code 10 20 30 30 20 10 30 30 30 10 10 10 16 / 20Which of the following is a valid functional interface in Java? Runnable Comparator Callable All of the above 17 / 20What is the significance of the @FunctionalInterface annotation? It ensures the interface cannot have more than one abstract method It ensures the interface can be used in lambda expressions It provides metadata for the compiler Both A and C 18 / 20Which feature of Java allows the use of methods that are not determined until runtime? Polymorphism Encapsulation Inheritance Abstraction 19 / 20What is the difference between Callable and Runnable? "Callable" can return a result, "Runnable" cannot "Runnable" can throw checked exceptions, "Callable" canno "Runnable" can return a result, "Callable" cannot "Callable" cannot throw checked exceptions, "Runnable" can 20 / 20What is the purpose of the volatile keyword in Java? To prevent a variable from being accessed by multiple threads To indicate that a variable's value will be modified by different threads To ensure a variable is not cached thread-locally Both B and C Your score isThe average score is 60% 0% Restart quiz