Question 1
Which keyword is used to prevent a method from being overridden in a subclass?
- static
- volatile
- final
- synchronized
- transient
Question 2
What is the primary purpose of the 'garbage collector' in Java?
- To optimize code execution speed
- To automatically manage memory by reclaiming unused objects
- To handle exceptions and errors
- To prevent memory leaks by allocating more memory
- To ensure code security against vulnerabilities
Question 3
Which data structure follows the Last-In-First-Out principle?
- Queue
- Linked List
- Tree
- Stack
- Heap
Question 4
What is the purpose of the 'interface' keyword in Java?
- To define a class constructor
- To create a concrete class
- To define a contract that classes can implement
- To declare a variable
- To create a package
Question 5
Which of the following is a valid way to create a new instance of a class called 'MyClass'?
- MyClass.new()
- create MyClass()
- new MyClass()
- MyClass()
- instanceof MyClass
Question 6
What is the role of the 'extends' keyword in Java?
- To implement an interface
- To define a new package
- To inherit properties and methods from another class
- To declare a constant variable
- To throw an exception
Question 7
Which of these is a primitive data type in Java?
- String
- Integer
- Boolean
- Array
- Object
Question 8
What is the purpose of the 'try-catch' block in Java?
- To define a loop
- To handle exceptions
- To create a new thread
- To define a conditional statement
- To declare a method
Question 9
What is the difference between '==' and '.equals()' in Java when comparing objects?
- '==' compares the values, '.equals()' compares the references
- '==' compares the references, '.equals()' compares the values based on the object's implementation
- Both compare the memory addresses
- Both compare the data types
- There is no difference
Question 10
What does the term 'polymorphism' refer to in object-oriented programming?
- The ability of an object to take on many forms
- The process of hiding data within a class
- The ability to create multiple threads
- The process of memory allocation
- The act of writing comments in code