Computer Fundamentals for Placements – Java MCQs with Answers
Q. 1 Which of the following is a correct declaration and initialization of an array in Java?
Check Solution
Ans: A
In Java, an array can be declared and initialized in a single line using the syntax dataType[] arrayName = {element1, element2, …};. The other options have incorrect syntax.
Q. 2 What is the correct way to define a constant variable in Java?
Check Solution
Ans: A
The keywords static and final are used together to create a constant in Java. static ensures it belongs to the class and final makes it a constant, whose value cannot be changed. The common practice is to have static final.
Q. 3 Which of these is not a Java keyword?
Check Solution
Ans: C
class, interface, and public are all reserved keywords in Java. String (with a capital S) is a class in Java’s standard library, but string (lowercase) is not a keyword.
Q. 4 What is the output of System.out.println(10 + 20 + Java”);?”
Check Solution
Ans: A
In Java, when an arithmetic operation is followed by a string concatenation, the arithmetic operation is performed first. So 10 + 20 becomes 30, and then it’s concatenated with “Java”.
Q. 5 Which of the following is a primitive data type in Java?
Check Solution
Ans: D
char is a primitive data type. String and Integer are classes in Java. Double is a wrapper class, while the primitive type is double (lowercase).
Q. 6 Which of the following access modifiers restricts a member to be accessed only within the same class and its subclasses?
Check Solution
Ans: C
The protected access modifier allows a member to be accessed within the same package and by subclasses of that class in other packages. private is only within the class, and public is accessible from anywhere.
Q. 7 What is the default value of an instance variable of type boolean?
Check Solution
Ans: B
For instance variables, if they are not explicitly initialized, boolean variables are automatically initialized to false.
Q. 8 Which exception is thrown when an attempt is made to divide an integer by zero?
Check Solution
Ans: A
ArithmeticException is a runtime exception that occurs when an arithmetic operation, like division by zero, is performed.
Q. 9 What is the output of the following code snippet? int x = 5; x++; System.out.print(x);
Check Solution
Ans: B
The x++ is a post-increment operator, which increases the value of x by 1. The new value, 6, is then printed to the console.
Q. 10 Which of these is the superclass of all classes in Java?
Check Solution
Ans: A
The java.lang.Object class is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
Next Topic: OOP Programming MCQs with Answers for Placements
Practice Aptitude Questions for Placements
Crack Placement Tests: Faster & Smarter
Adaptive Practice | Real Time Insights | Resume your Progress
