-
Which keyword is used to specify that a method does not return any value in Java?
A) void
B) null
C) none
D) emptyAnswer: A) void
-
What is the correct way to declare a constant variable in Java?
A) const int MAX_VALUE = 100;
B) final int MAX_VALUE = 100;
C) static int MAX_VALUE = 100;
D) final constant int MAX_VALUE = 100;Answer: B) final int MAX_VALUE = 100;
-
Which of the following is used to read input from the user in Java?
A) System.readInput()
B) Console.readLine()
C) Scanner
D) BufferedReaderAnswer: C) Scanner
-
What does the 'super' keyword refer to in Java?
A) It refers to the superclass of the current class.
B) It refers to the subclass of the current class.
C) It refers to the base class of the current class.
D) It refers to the derived class of the current class.Answer: A) It refers to the superclass of the current class.
-
Which of the following is true about the 'break' statement in Java?
A) It is used to exit a loop or switch statement.
B) It is used to skip the remaining code in a loop and continue to the next iteration.
C) It is used to terminate the program abruptly.
D) It is used to define a label in Java.Answer: A) It is used to exit a loop or switch statement.
-
What is the correct way to declare and initialize an array in Java?
A) int[] arr = {1, 2, 3, 4, 5};
B) array arr = {1, 2, 3, 4, 5};
C) int arr[] = [1, 2, 3, 4, 5];
D) int arr[] = new int[5] {1, 2, 3, 4, 5};Answer: A) int[] arr = {1, 2, 3, 4, 5};
-
Which method is called when an object is created in Java?
A) finalize()
B) constructor()
C) new()
D) initialize()Answer: B) constructor()
-
What is the correct way to compare two strings in Java for equality?
A) str1 == str2
B) str1.equals(str2)
C) str1.compareTo(str2)
D) str1.equal(str2)Answer: B) str1.equals(str2)
-
What is the purpose of the 'try', 'catch', and 'finally' blocks in Java?
A) To handle exceptions
B) To define loops
C) To declare variables
D) To execute code asynchronouslyAnswer: A) To handle exceptions
-
Which of the following is true about Java Virtual Machine (JVM)?
A) It is hardware-specific.
B) It directly executes Java source code.
C) It ensures platform independence.
D) It is responsible for compiling Java code.Answer: A) It is hardware-specific.
Comments