1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Question 1: Which component of Java is responsible for executing Java bytecode?
A) JDK (Java Development Kit)
B) JVM (Java Virtual Machine)
C) JRE (Java Runtime Environment) D) JAVAC (Java Compiler)
B) JVM (Java Virtual Machine)
Question 2: What is the default initial value of an uninitialized instance variable of type int in Java?
A) null
B) 0
C) Garbage value
D) Undefined
B) 0
Question 3: Which access modifier makes a class member accessible only within its own class?
A) public
B) protected
C) private
D) default (package-private)
C) private
Question 4: Which keyword is used by a class to inherit another class in Java?
A) implements
B) extends
C) inherits
D) super
B) extends
Question 5: Which keyword is used to declare an interface in Java?
A) class
B) abstract
C) interface
D) implements
C) interface
Question 6: What is the return type of a constructor in Java?
A) void
B) int
C) Object
D) Constructors do not have a return type
D) Constructors do not have a return type
Question 7: Which of the following data types is NOT a primitive type in Java?
A) int
B) boolean
C) String
D) double
C) String
Question 8: What happens when you declare a variable as final in Java?
A) It can only be accessed within its method
B) Its value cannot be modified once assigned
C) It automatically becomes static
D) It gets allocated in stack memory permanently
B) Its value cannot be modified once assigned
Question 9: Which method signature is the correct entry point for a standard Java standalone application?
A) public static void main(String[] args)
B) public void main(String[] args)
C) public static int main(String[] args)
D) static void main(String args)
A) public static void main(String[] args)
Question 10: Which OOP principle hides internal implementation details and exposes only necessary functionality?
A) Inheritance
B) Polymorphism
C) Abstraction
D) Association
C) Abstraction
Question 11: Can an abstract class in Java be instantiated using the 'new' operator directly?
A) Yes, always
B) No, abstract classes cannot be instantiated
C) Yes, if it has a constructor
D) Yes, if all methods have implementations
B) No, abstract classes cannot be instantiated
Question 12: Which collection interface in Java stores elements as key-value pairs?
A) List
B) Set
C) Map
D) Queue
C) Map
Question 13: Which keyword is used to handle exceptions in Java alongside try?
A) catch
B) throw
C) throws
D) error
A) catch
Question 14: Which keyword is used in a method signature to declare that it might throw exceptions?
A) throw
B) throws
C) catch
D) try
B) throws
Question 15: What is the base class for all classes in Java?
A) Class
B) Object
C) System
D) Root
B) Object
Question 16: Which exception is thrown when attempting to divide an integer by zero in Java?
A) NullPointerException
B) ArithmeticException
C) NumberFormatException
D) IllegalArgumentException
B) ArithmeticException
Question 17: Which memory structure in Java is used for object storage?
A) Stack memory
B) Heap memory
C) Method area
D) PC Register
B) Heap memory
Question 18: What is Garbage Collection in Java?
A) Manual memory deallocation by developer
B) Automatic reclamation of memory allocated to unreferenced objects
C) Deleting temporary source files
D) Cleaning up unused local stack frames
B) Automatic reclamation of memory allocated to unreferenced objects
Question 19: Which of the following collection types does NOT allow duplicate elements?
A) ArrayList
B) LinkedList
C) HashSet
D) Vector
C) HashSet
Question 20: Which operator is used to create an instance of a class in Java?
A) new
B) create
C) alloc
D) instance
A) new
Question 21: What is the output of System.out.println(10 + 20 + "Java");?
A) Java1020
B) 30Java
C) 1020Java
D) Compilation Error
B) 30Java
Question 22: What is the output of System.out.println("Java" + 10 + 20);?
A) Java30
B) Java1020
C) 30Java
D) Compilation Error
B) Java1020
Question 23: Which loop in Java evaluates the boolean condition BEFORE executing the loop body?
A) while loop
B) do-while loop
C) post-test loop
D) none of the above
A) while loop
Question 24: Which keyword is used to access members of a superclass from a subclass?
A) this
B) super
C) parent
D) base
B) super
Question 25: Which statement terminates a loop or switch statement execution immediately?
A) break
B) continue
C) return
D) exit
A) break
Question 26: Which of the following is the correct syntax for the Java ternary operator?
A) int max = (a > b) : a ? b;
B) int max = if (a > b) a else b;
C) int max = (a > b) ? a , b;
D) int max = (a > b) ? a : b;
D) int max = (a > b) ? a : b;
Question 27: Which statement accurately compares StringBuilder and String in Java?
A) String is mutable, StringBuilder is immutable
B) StringBuilder is thread-safe, String is not
C) StringBuilder is generally more efficient in loops
D) String operations are always faster than StringBuilder
C) StringBuilder is generally more efficient in loops
Question 28: Can a final class in Java be extended?
A) No, it cannot be extended
B) Yes, but only within the same package
C) Yes, if all its methods are public
D) Yes, by using the super keyword
A) No, it cannot be extended
Question 29: What is the main difference between == and .equals() in Java? A) == compares references, .equals() compares content
B) == compares content, .equals() compares references
C) They are completely identical in function
D) .equals() can only be used with primitive types
A) == compares references, .equals() compares content
Question 30: Why are setters used in encapsulation?
A) To make fields public
B) To make a class final
C) To prevent invalid object states
D) To speed up execution time
C) To prevent invalid object states
Question 31: What kind of constructor is used in the following code pattern? class Test { private Test() { System.out.println("Private constructor"); } public static Test getInstance() { return new Test(); } }
A) Public constructor
B) Private constructor
C) Default constructor
D) Protected constructor
B) Private constructor
Question 32: Does Java support multiple inheritance for classes?
A) Yes, using the extends keyword with comma separation
B) Yes, but only for abstract classes
C) Yes, if all parent classes are final
D) No, not supported for classes
D) No, not supported for classes
Question 33: Can an interface extend another interface in Java?
A) No, interfaces cannot use inheritance
B) Yes, but an interface can extend only one interface
C) Yes, interfaces can extend one or more other interfaces
D) Only if the parent interface is functional
C) Yes, interfaces can extend one or more other interfaces
Question 34: What is the benefit of using the @Override annotation in Java?
A) It improves runtime performance
B) It automatically generates method implementations
C) It prevents methods from being called directly
D) It catches mismatched signatures as errors
D) It catches mismatched signatures as errors
Question 35: How is method overloading resolved in Java?
A) Dynamically at runtime based on the actual object type
B) It is resolved at compile time based on the number, types, and order of arguments
C) By checking the return type of the method
D) Randomly during execution
B) It is resolved at compile time based on the number, types, and order of arguments
Question 36: What is a static method in Java?
A) A method that is abstract
B) A method that can be overridden
C) A method that belongs to the class rather than any instance
D) A method that cannot be called
C) A method that belongs to the class rather than any instance
Question 37: Can a class have multiple constructors in Java?
A) No, constructors cannot be overloaded
B) Yes, through constructor overloading
C) No, only one constructor is allowed
D) Yes, but only if they have the same parameters
B) Yes, through constructor overloading
Question 38: A contract that defines what methods a class must implement: A) A Record
B) UML diagram
C) An Interface
D) A special type of constructor
C) An Interface
Question 39: Which loop guarantees that its body executes at least once? A) do-while loop
B) while loop
C) for loop
D) enhanced for loop
A) do-while loop
Question 40: Subtypes must be substitutable for their base types without altering correctness:
A) Liskov Substitution Principle
B) Open/Closed Principle
C) Single Responsibility Principle
D) Dependency Inversion Principle (DIP)
A) Liskov Substitution Principle
Question 41: What is type casting in OOP?
A) Changing the data type of a variable's declaration permanently
B) Creating a new instance of a class by using the new keyword
C) Deleting an object
D) Converting a reference from one compatible type to another
D) Converting a reference from one compatible type to another
Question 42: Which design principle suggests that a class should have only one reason to change?
A) Open/Closed Principle
B) Liskov Substitution Principle
C) Single Responsibility Principle
D) Interface Segregation Principle
C) Single Responsibility Principle
Question 43: Which statement about Java String objects is true?
A) Strings are immutable; modifying methods return new String objects
B) Strings are mutable once created
C) Strings are stored only in the heap, never in a string pool
D) String concatenation with + always modifies the original object in place
A) Strings are immutable; modifying methods return new String objects
Question 44: What is the purpose of the 'this' keyword in Java?
A) To define static methods
B) To create new objects in the heap memory
C) To refer to the current object
D) To call parent class methods or constructor
C) To refer to the current object
Question 45: What does the following code print? String a = "hello"; String b = "hello"; System.out.println(a == b);
A) true, because both reference the same interned String
B) false, because == always compares object identity for Strings
C) false, because Strings are never equal with ==
D) It throws a compile-time error
A) true, because both reference the same interned String
Question 46: Which of the following best explains why Java uses pass-by-value even for objects?
A) Java always copies the entire object when passed to a method
B) A copy of the reference (memory address) is passed
C) Primitives are passed by reference while objects are passed by value
D) Objects are passed by reference, so the original object changes when modified
B) A copy of the reference (memory address) is passed
Question 47: Why might a class expose a getter but deliberately omit a setter for a particular field?
A) This is not allowed in Java; every getter requires a matching setter
B) To make that field effectively read-only after construction
C) To force the compiler to auto-generate a setter
D) Because Java requires symmetric getter/setter pairs
B) To make that field effectively read-only after construction
Question 48: Can interfaces have variables?
A) No, interfaces cannot declare variables because they are limited to defining method contracts.
B) Yes, interfaces can declare instance, static, and mutable variables just like regular classes.
C) Yes, but they are implicitly public, static, and final.
D) Only private variables
C) Yes, but they are implicitly public, static, and final.
Question 49: Which of the following best describes inheritance in OOP?
A) One class acquires properties of another class
B) Calling methods on objects with multiple forms
C) Hiding implementation details
D) Creating multiple objects from one class or interface
A) One class acquires properties of another class
Question 50: What is the result of this code? class Parent { final void display() { System.out.println("Parent display"); } } class Child extends Parent { void display() { System.out.println("Child display"); } } public class Main { public static void main(String[] args) { Child c = new Child(); c.display(); } }
A) Runtime error
B) Parent display
C) Child display
D) Compilation error
D) Compilation error