Class in Object Oriented Programming (OOPs) MCQ Questions and Answers
1. Which of the following best defines a class in OOP?
A) A collection of variables only
B) A function that executes specific tasks
C) A blueprint or template for creating objects
D) A data type with no behavior
Answer: C) A blueprint or template for creating objects
2. In OOP, what is an instance of a class called?
A) Method
B) Function
C) Object
D) Constructor
Answer: C) Object
3. Which keyword is used to define a class in C++?
A) struct
B) define
C) class
D) object
Answer: C) class
4. In Python, what is the first parameter of every instance method typically named?
A) class
B) this
C) self
D) init
Answer: C) self
5. Which of the following is not a component of a class?
A) Methods
B) Data members
C) Objects
D) Constructors
Answer: C) Objects
6. What is encapsulation in the context of classes?
A) Binding data and functions together
B) Hiding data inside loops
C) Reusing code from another class
D) Separating code into multiple files
Answer: A) Binding data and functions together
7. The process of defining a class within another class is called:
A) Multiple inheritance
B) Nested class
C) Encapsulation
D) Data abstraction
Answer: B) Nested class
8. Which member of a class can be accessed without creating an object?
A) Instance variable
B) Non-static method
C) Static member
D) Private member
Answer: C) Static member
9. The function that initializes the data members of a class is called:
A) Destructor
B) Initializer
C) Constructor
D) Allocator
Answer: C) Constructor
10. What is the default access specifier for members of a class in C++?
A) Public
B) Private
C) Protected
D) Internal
Answer: B) Private
11. Which of the following describes the “object” created from a class?
A) Abstract entity
B) Concrete instance
C) Logical template
D) Code block
Answer: B) Concrete instance
12. Which of the following is true about constructors in Java?
A) They must have a return type
B) They are automatically called when an object is created
C) They can be declared static
D) They can be inherited
Answer: B) They are automatically called when an object is created
13. In OOP, class members declared as private are:
A) Accessible only within the class
B) Accessible by derived classes
C) Accessible from any function
D) Accessible by all objects
Answer: A) Accessible only within the class
14. A class that cannot be instantiated directly is known as a:
A) Sealed class
B) Abstract class
C) Static class
D) Derived class
Answer: B) Abstract class
15. Which of the following is true for a destructor in C++?
A) It has the same name as the class with a tilde (~)
B) It can have parameters
C) It can be overloaded
D) It returns a value
Answer: A) It has the same name as the class with a tilde (~)
16. What happens when you declare a class but do not define it?
A) It throws a compile-time error
B) It is treated as an incomplete type
C) It creates a null object
D) It executes an empty constructor
Answer: B) It is treated as an incomplete type
17. Which of the following describes “data abstraction”?
A) Exposing all implementation details
B) Showing only essential features and hiding the details
C) Writing multiple versions of the same method
D) Allowing multiple inheritance
Answer: B) Showing only essential features and hiding the details
18. Which keyword is used to create an object from a class in Java?
A) new
B) make
C) object
D) class
Answer: A) new
19. In OOP, what is meant by “method overloading”?
A) Defining multiple methods with the same name but different parameters
B) Using the same variable in multiple classes
C) Defining one method in different classes
D) Using multiple inheritance
Answer: A) Defining multiple methods with the same name but different parameters
20. Which of the following is a characteristic of a well-designed class?
A) High cohesion and low coupling
B) High coupling and high cohesion
C) Low cohesion and low coupling
D) Low cohesion and high coupling
Answer: A) High cohesion and low coupling
21. In C++, what is the role of the this pointer in a class?
A) It points to the parent class
B) It refers to the current instance of the class
C) It points to the static members
D) It holds the address of all objects
Answer: B) It refers to the current instance of the class
22. Which of the following is true for a class constructor?
A) It is called automatically when an object is destroyed
B) It must have a return type
C) It executes only once per class definition
D) It is invoked when an object is created
Answer: D) It is invoked when an object is created
23. When is a copy constructor called in C++?
A) When two classes are merged
B) When an object is copied or passed by value
C) When a class is inherited
D) When a static method is called
Answer: B) When an object is copied or passed by value
24. Which of the following members of a class are shared among all instances of that class?
A) Instance variables
B) Static variables
C) Private methods
D) Constructors
Answer: B) Static variables
25. The main difference between a class and a structure in C++ is:
A) Structures cannot contain functions
B) Classes cannot contain variables
C) Classes have private members by default
D) Structures are used only for inheritance
Answer: C) Classes have private members by default
26. In Java, if no constructor is defined in a class, the compiler:
A) Throws a compilation error
B) Automatically provides a default constructor
C) Ignores object creation
D) Calls a destructor
Answer: B) Automatically provides a default constructor
27. A member function that is defined outside a class using the scope resolution operator (::) must be:
A) Declared static
B) Declared virtual
C) Declared within the class definition first
D) Defined with public access
Answer: C) Declared within the class definition first
28. Which type of class member can access private members of another class?
A) Friend function
B) Static function
C) Public function
D) Virtual function
Answer: A) Friend function
29. Which of the following cannot be declared as static in a class?
A) Data member
B) Member function
C) Constructor
D) Variable inside a method
Answer: C) Constructor
30. What is the purpose of an access specifier in a class?
A) To specify the return type of a function
B) To define where the class is stored
C) To control visibility of class members
D) To allocate memory dynamically
Answer: C) To control visibility of class members
31. What happens when a destructor is made private in a class?
A) The class cannot have objects
B) The class can only be instantiated statically
C) The class cannot be instantiated outside
D) The destructor is ignored
Answer: C) The class cannot be instantiated outside
32. Which access specifier allows class members to be accessed within the same class and its derived classes?
A) Public
B) Protected
C) Private
D) Internal
Answer: B) Protected
33. Which among the following is a characteristic of an immutable class?
A) Its data members can be modified after creation
B) It cannot be instantiated
C) Its data members cannot be changed once assigned
D) It can inherit from multiple classes
Answer: C) Its data members cannot be changed once assigned
34. In OOP, what is meant by “composition”?
A) A class containing objects of other classes as members
B) Creating a hierarchy of derived classes
C) Hiding implementation details
D) Reusing code through inheritance
Answer: A) A class containing objects of other classes as members
35. Which of the following can be declared virtual in C++?
A) Constructor
B) Destructor
C) Static function
D) Friend function
Answer: B) Destructor
36. A class that can be used as a base but not instantiated directly is called:
A) Concrete class
B) Static class
C) Abstract class
D) Friend class
Answer: C) Abstract class
37. The process of combining data and behavior in a single unit is known as:
A) Data abstraction
B) Encapsulation
C) Inheritance
D) Polymorphism
Answer: B) Encapsulation
38. Which statement about static methods is true?
A) They cannot access static variables
B) They can access only static members
C) They require an object to be called
D) They always return an integer
Answer: B) They can access only static members
39. In Java, how many public classes can exist in a single source file?
A) Unlimited
B) One
C) Two
D) Depends on compiler version
Answer: B) One
40. What is a key difference between a class and an interface in OOP?
A) A class defines behavior, while an interface only declares it
B) A class cannot contain methods
C) Interfaces can hold data members
D) Classes cannot implement interfaces
Answer: A) A class defines behavior, while an interface only declares it
41. Which of the following is true about constructors and destructors in a class?
A) Both can return values
B) Both can be overloaded
C) Only constructors can be overloaded
D) Both are automatically called by the user
Answer: C) Only constructors can be overloaded
42. What happens if a class has no user-defined destructor in C++?
A) Program fails to compile
B) The compiler automatically generates a default destructor
C) No memory is released
D) It must be explicitly defined
Answer: B) The compiler automatically generates a default destructor
43. Which of the following statements is true about a static constructor in C#?
A) It can take parameters
B) It executes every time an object is created
C) It executes only once for the entire class
D) It can be overloaded
Answer: C) It executes only once for the entire class
44. Which of these cannot be used to define a class in Python?
A) The class keyword
B) The def keyword
C) The object base class
D) Indentation-based blocks
Answer: B) The def keyword
45. Which of the following is true regarding a friend class in C++?
A) It inherits from another class
B) It can access private and protected members of another class
C) It can only access public data
D) It must be declared in the same file
Answer: B) It can access private and protected members of another class
46. What is the main use of the “final” keyword in Java when applied to a class?
A) To prevent inheritance
B) To make the class abstract
C) To allow multiple instances
D) To make class members private
Answer: A) To prevent inheritance
47. A class that defines only abstract methods and no data members is called:
A) Sealed class
B) Interface
C) Derived class
D) Anonymous class
Answer: B) Interface
48. What is a nested class in Java?
A) A class defined outside a package
B) A class defined inside another class
C) A class that cannot have a constructor
D) A class with only static methods
Answer: B) A class defined inside another class
49. Which among the following cannot be inherited by a subclass?
A) Public methods
B) Private methods
C) Protected methods
D) Static methods
Answer: B) Private methods
50. The term “instance variable” refers to:
A) A variable shared among all instances
B) A variable declared inside a method
C) A variable unique to each object of a class
D) A variable that cannot be modified
Answer: C) A variable unique to each object of a class
51. Which of the following is the correct statement about a class template in C++?
A) It allows creating classes with fixed data types only
B) It supports generic programming by using placeholders
C) It is used to define only static members
D) It must inherit from another class
Answer: B) It supports generic programming by using placeholders
52. What is an inline member function in a class?
A) A function declared outside the class
B) A function that executes in a separate thread
C) A function defined inside the class definition
D) A virtual function
Answer: C) A function defined inside the class definition
53. The keyword “virtual” in C++ indicates that:
A) A function can be accessed from anywhere
B) A function can be overridden in a derived class
C) A class cannot be instantiated
D) A variable is temporary
Answer: B) A function can be overridden in a derived class
54. Which of the following can access both private and public members of two classes?
A) Friend function
B) Virtual function
C) Static function
D) Derived class
Answer: A) Friend function
55. What is the main feature of an object created from a class?
A) It defines methods
B) It holds actual data and state
C) It serves as a template
D) It cannot be modified
Answer: B) It holds actual data and state
56. In OOP, which principle allows a class to hide its implementation details from the user?
A) Abstraction
B) Inheritance
C) Overloading
D) Polymorphism
Answer: A) Abstraction
57. What is a class specification that cannot be extended called?
A) Abstract class
B) Final class
C) Parent class
D) Virtual class
Answer: B) Final class
58. Which of the following correctly describes a default constructor?
A) A constructor that takes no parameters
B) A constructor that initializes static members only
C) A constructor that returns an object
D) A constructor that calls another class
Answer: A) A constructor that takes no parameters
59. Which among the following correctly explains “object slicing”?
A) Copying all data members to another object
B) Loss of derived class data when assigned to a base class object
C) Creating multiple instances of a single class
D) Overloading of functions inside a class
Answer: B) Loss of derived class data when assigned to a base class object
60. What is the use of a static block in Java classes?
A) To define constants
B) To initialize static data members
C) To declare constructors
D) To override inherited methods
Answer: B) To initialize static data members
61. Which of the following members of a class can be accessed by objects of that class directly?
A) Private members
B) Protected members
C) Public members
D) Static private members
Answer: C) Public members
62. In which of the following scenarios is a destructor executed automatically?
A) When the program starts
B) When an object goes out of scope
C) When a constructor is called
D) When the class is declared
Answer: B) When an object goes out of scope
63. Which of the following is not a property of a class?
A) It defines attributes
B) It defines behaviors
C) It is a real instance
D) It serves as a template
Answer: C) It is a real instance
64. Which operator is used in C++ to dynamically allocate memory for a class object?
A) malloc
B) alloc
C) new
D) create
Answer: C) new
65. What does a copy constructor in C++ take as a parameter?
A) Integer
B) Object by value
C) Object by reference
D) Array
Answer: C) Object by reference
66. What is the relationship between a class and an object?
A) Object is a function inside a class
B) Class is an instance of an object
C) Object is an instance of a class
D) They are the same thing
Answer: C) Object is an instance of a class
67. Which keyword in Java is used to inherit a class?
A) implement
B) extends
C) inherits
D) superclass
Answer: B) extends
68. In Python, what is the role of the __init__() method in a class?
A) To destroy the object
B) To initialize object attributes when an instance is created
C) To define private variables
D) To return the object reference
Answer: B) To initialize object attributes when an instance is created
69. What is the result if a class contains only private constructors?
A) It cannot be inherited
B) Objects cannot be created from outside the class
C) It must be abstract
D) It is automatically final
Answer: B) Objects cannot be created from outside the class
70. Which function in C++ is called automatically before program termination to clean up static objects?
A) Destructor
B) Finalizer
C) Static destructor
D) Global destructor
Answer: A) Destructor
71. Which of the following is a characteristic of a well-encapsulated class?
A) All members are public
B) Data is hidden and accessed through methods
C) No functions are allowed
D) Data members are directly modifiable
Answer: B) Data is hidden and accessed through methods
72. What is the difference between a class and an object in OOP?
A) Class is abstract; object is concrete
B) Class stores data; object defines structure
C) Both are the same concept
D) Class exists at runtime; object exists at compile time
Answer: A) Class is abstract; object is concrete
73. Which type of constructor is called automatically when an object is created without any arguments?
A) Parameterized constructor
B) Copy constructor
C) Default constructor
D) Static constructor
Answer: C) Default constructor
74. What will happen if you declare a method as both static and virtual in C++?
A) It will work normally
B) It will throw a compile-time error
C) It will override automatically
D) It will act as a friend function
Answer: B) It will throw a compile-time error
75. What is the main purpose of a destructor in a class?
A) To allocate memory
B) To initialize static variables
C) To release resources or memory used by an object
D) To create another object
Answer: C) To release resources or memory used by an object
76. Which among the following is not allowed in an abstract class?
A) Virtual methods
B) Pure virtual methods
C) Object instantiation
D) Derived classes
Answer: C) Object instantiation
77. What is meant by “method overriding”?
A) Defining a method in the base class
B) Defining multiple methods with same name but different parameters
C) Redefining a method of a parent class in the child class
D) Declaring a static function
Answer: C) Redefining a method of a parent class in the child class
78. In Java, which access specifier allows visibility within the same package but not outside it?
A) public
B) protected
C) private
D) default (package-private)
Answer: D) default (package-private)
79. What will happen if you do not provide a copy constructor in your class?
A) The compiler provides a default one
B) The program will not compile
C) It cannot be inherited
D) The destructor is called instead
Answer: A) The compiler provides a default one
80. What is an inner class that can access outer class’s private members called in Java?
A) Public class
B) Nested class
C) Inner class (non-static)
D) Static class
Answer: C) Inner class (non-static)
81. Which of the following statements about abstract classes is true?
A) They can be instantiated directly
B) They can contain both abstract and concrete methods
C) They cannot have any constructors
D) They must contain only static members
Answer: B) They can contain both abstract and concrete methods
82. Which among the following is not a type of relationship between classes in OOP?
A) Association
B) Aggregation
C) Composition
D) Compilation
Answer: D) Compilation
83. What is the difference between composition and aggregation?
A) Composition represents “has-a” with strong ownership, aggregation represents weak ownership
B) Aggregation is a type of inheritance
C) Composition allows independent object existence
D) Aggregation means objects cannot be destroyed
Answer: A) Composition represents “has-a” with strong ownership, aggregation represents weak ownership
84. Which of the following keywords in Java prevents a method from being overridden in a subclass?
A) static
B) abstract
C) final
D) private
Answer: C) final
85. What will happen if a class in C++ has no public constructor?
A) It cannot be inherited
B) Objects cannot be created outside the class
C) It becomes an abstract class
D) It cannot contain static members
Answer: B) Objects cannot be created outside the class
86. Which OOP principle allows one class to acquire properties and behaviors of another?
A) Encapsulation
B) Inheritance
C) Abstraction
D) Polymorphism
Answer: B) Inheritance
87. Which of the following best defines an interface in Java?
A) A class that contains only static methods
B) A contract specifying methods without implementation
C) A special class with constructors
D) A class containing only private members
Answer: B) A contract specifying methods without implementation
88. When does dynamic method dispatch occur in OOP?
A) At compile time
B) At runtime
C) During linking
D) During class definition
Answer: B) At runtime
89. Which of the following can be used to prevent class inheritance in C++?
A) Making the class abstract
B) Declaring the class as final
C) Making all methods private
D) Using multiple inheritance
Answer: B) Declaring the class as final
90. What happens when two classes have methods with the same name but are unrelated by inheritance?
A) Compile-time polymorphism
B) Runtime polymorphism
C) Method overriding
D) Dynamic binding
Answer: A) Compile-time polymorphism
91. What does the “sealed” keyword indicate in C#?
A) The class cannot be inherited
B) The class cannot have static members
C) The class cannot be instantiated
D) The class cannot have a destructor
Answer: A) The class cannot be inherited
92. Which OOP principle ensures that changes in one class have minimal impact on others?
A) Abstraction
B) Coupling
C) Cohesion
D) Encapsulation
Answer: D) Encapsulation
93. Which method in Java is called just before an object is garbage collected?
A) finalize()
B) dispose()
C) destroy()
D) clear()
Answer: A) finalize()
94. What is meant by “class loader” in Java?
A) A program that deletes unused classes
B) A mechanism that loads classes into JVM dynamically
C) A compiler optimization tool
D) A constructor function
Answer: B) A mechanism that loads classes into JVM dynamically
95. Which of the following statements about static nested classes is true in Java?
A) They can access instance members of the outer class
B) They can be instantiated without an outer class object
C) They must be declared abstract
D) They can only contain static variables
Answer: B) They can be instantiated without an outer class object
96. Which of the following best explains the “Single Responsibility Principle”?
A) A class should perform one and only one function
B) A class should inherit from multiple parents
C) A class should expose all its data
D) A class should manage all program tasks
Answer: A) A class should perform one and only one function
97. In which situation is a copy constructor explicitly invoked?
A) When using assignment operator
B) When passing an object by value
C) When creating an abstract class
D) When deleting an object
Answer: B) When passing an object by value
98. Which OOP concept allows classes with similar characteristics to share a common base class?
A) Abstraction
B) Encapsulation
C) Inheritance
D) Polymorphism
Answer: C) Inheritance
99. In C++, how many destructors can a class have?
A) One
B) Two
C) As many as needed
D) Zero
Answer: A) One
100. Which of the following best defines polymorphism in OOP?
A) The ability of different objects to respond differently to the same message
B) The process of binding data and methods
C) The use of multiple inheritance
D) The creation of multiple constructors in one class
Answer: A) The ability of different objects to respond differently to the same message
