1. Which keyword is used to declare a constant in Java?
Explanation: The `final` keyword is used to declare a constant in Java, meaning its value cannot be changed after initialization.
Image Explanation.
Image Explanation.
2. Which of the following is NOT a primitive data type in Java?
Explanation: String is a class in Java, representing a sequence of characters, not a primitive data type.
3. What is the purpose of the `new` keyword in Java?
Explanation: The `new` keyword is used to create a new instance (object) of a class, allocating memory to store its data.
4. Which access modifier provides the highest level of visibility in Java?
Explanation: The `public` access modifier allows members of a class to be accessed from any other class, regardless of the package.
5. What is method overriding in Java?
Explanation: Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass, with the same name and parameters.
6. What is the role of the 'static' keyword in Java?
Explanation: The `static` keyword signifies that a member (variable or method) belongs to the class itself, rather than to any particular instance (object) of the class.
7. Which statement is used to handle exceptions in Java?
Explanation: The `try-catch` block is used to handle exceptions. Code that might throw an exception is placed inside the try block, and code to handle that exception is placed inside the catch block.
8. What is the purpose of the `this` keyword in Java?
Explanation: The `this` keyword is a reference to the current object and allows you to access its methods and attributes.
9. Which interface represents a collection that does not allow duplicate elements?
Explanation: The `Set` interface represents a collection that doesn't allow duplicate elements, ensuring uniqueness among the elements it contains.
10. Which is the correct way to iterate an ArrayList?
Explanation: The enhanced `for` loop (for-each) provides a way to iterate each object in a collection, in this case, an `ArrayList` without using index based access.