What is a class in C++?
B
A way to store integers
C
A user-defined data type that groups variables and functions
Analysis & Theory
A class is a user-defined type in C++ that can group data members and member functions together.
Which access specifier allows members to be accessed from outside the class?
Analysis & Theory
`public` members of a class can be accessed from outside the class.
What is the default access specifier for class members in C++?
Analysis & Theory
By default, class members are `private` in C++.
How is an object created from a class?
A
By using the `new` keyword
B
By declaring a variable of class type
C
By calling the constructor directly
D
Using `class.create()` method
Analysis & Theory
Objects are created by declaring a variable of the class type. For example: `MyClass obj;`
Which function is automatically called when an object is created?
Analysis & Theory
A **constructor** is automatically invoked when an object is created.
Which of the following defines a class in C++?
B
`new class ClassName {}`
Analysis & Theory
The correct syntax to define a class is: `class ClassName { };`
Which of the following statements is true about destructors?
A
They can take arguments
C
They do not take parameters and are not overloaded
D
They are called using a function call
Analysis & Theory
Destructors cannot take arguments or be overloaded; they clean up when an object is destroyed.
Which of the following creates an object of a class `Person`?
Analysis & Theory
Object creation from a class is done using the syntax `Person obj;`
What is a member function?
A
A function that is defined outside the class
B
A function inside a class that acts on class data
Analysis & Theory
A **member function** is a function defined inside a class that operates on its members.
How can a class function access private data members?
B
It cannot access private members
C
By being a friend function
D
Because it is a member of the class
Analysis & Theory
Member functions can access private data members directly since they are part of the class.