11.) What is the main difference between a class and an object in Java?
A) A class is a blueprint, while an object is an instance of a class.
B) A class is an instance of an object, while an object is a blueprint.
C) A class and an object are the same thing.
D) A class defines attributes, while an object defines methods.
12.) Which of the following best describes the concept of data abstraction in Java?
A) Hiding the internal implementation details of an object
B) Accessing object attributes using the “this” keyword
C) Creating a new class based on an existing class
D) Using “get” and “set” methods for data manipulation
13.) Which section of a class contains the class’s attributes and instance variables?
A) Method section
B) Object section
C) Instance section
D) Field section
14.) What is the purpose of the “toString” method in Java?
A) To convert a class to a string representation
B) To convert an object to an integer
C) To compare two objects for equality
D) To create a new object from an existing one
15.) What is a default constructor in Java?
A) A constructor with no parameters that are provided by the compiler
B) A constructor that is automatically generated for static methods
C) A constructor that creates a new instance of a class
D) A constructor with the “default” access modifier
16.) Which keyword is used to access the superclass’s members (fields and methods) from a subclass?
A) super
B) this
C) parent
D) base
17.) In Java, can an object of a subclass be assigned to a variable of the superclass type?
A) No, it will result in a compilation error.
B) Yes, but only if the subclass overrides superclass methods.
C) Yes, this is allowed and is called polymorphism.
D) Yes, but only if the subclass has the same name as the superclass.
18.) Which access modifier makes a class member accessible only within the same class?
A) private
B) protected
C) public
D) default (package-private)
19.) What is the purpose of a “getter” method in Java?
A) To modify the value of an attribute
B) To provide access to the value of an attribute
C) To create a new instance of a class
D) To override superclass methods
20.) What is the role of the “equals” method in Java?
A) To compare the memory addresses of two objects
B) To compare the attributes of two objects for equality
C) To create a new instance of a class
D) To override superclass methods
Related