WorksheetsC++ Classes and Objects Quiz
Total questions: 60
Worksheet time: 30mins
Which of the following is the correct way to declare an object of a class `Student`?
Student s1;
Student();
object Student;
s1 Student;
If `class Car{ };`, how many objects are created with `Car c1, c2, c3;`?
1
2
3
0
Objects are instances of a:
Function
Class
Variable
Array
An object is created in:
Runtime only
Compile time only
Both runtime and compile time
Neither
Which keyword is required to declare an object?
object
instance
None, only class name is needed
declare
Multiple objects of the same class share:
Different member functions
Same member functions
Both different and same
None
Which of the following is true about object declaration?
Must use new keyword
May be declared like variables
Must always be initialized
None
If `Employee e1;` is declared inside main, its scope is:
Global
Local to main
Class scope
None
Which of the following is not an access specifier in C++?
public
private
protected
secured
By default, members of a class are:
public
private
protected
static
Which access specifier allows access inside the class only?
public
private
protected
none
Which access specifier allows inheritance but restricts access outside?
public
private
protected
friend
Which access specifier makes members accessible everywhere?
private
protected
public
static
Protected members are accessible in:
Same class only
Derived classes only
Friend functions only
Both same & derived classes
Access specifiers control:
Data hiding
Inheritance mode
Function definition
Compiler optimization
Which of the following access levels has least visibility?
public
private
protected
friend
Can private members be accessed directly outside the class?
Yes
No
Only in static functions
Only in inline functions
Protected members are most useful in:
Encapsulation
Inheritance
Friend functions
Static functions
A member function can be defined:
Inside class
Outside class
Both
None
Member function defined inside a class is:
Inline by default
Static by default
Virtual by default
None
The scope resolution operator `::` is used when:
Defining function outside class
Accessing private members
Declaring objects
None
Defining functions outside class helps in:
Reducing compilation time
Improving readability
Avoiding inlining
All of these
Which keyword is not used for defining a member function?
return_type
class_name::
function_name
object
Member functions inside a class automatically become:
Static
Inline
Friend
Const
Which operator links a function to a class?
->
.
::
:
Inline functions are usually defined:
In header file
In .cpp file
Both
None
Which of the following is not suitable for inline?
Short functions
Recursive functions
Accessor functions
Getters
The compiler may ignore inline request if function is:
Large in size
Recursive
Contains loops
All
Inline functions reduce:
Execution speed
Function call overhead
Memory usage
None
Inline keyword is:
A request, not a command
Mandatory instruction
Compiler directive
None
Static data members of a class are stored in:
Object memory
Class memory
Shared memory
Global memory
Static variables inside a class are initialized:
Inside constructor
Outside class
With object creation
None
Static data members are:
Shared by all objects
Unique per object
Not accessible
Constant only
Static member function can access:
Only static members
Only private members
All members
None
Static functions do not have:
Access to static members
this pointer
Scope resolution
Return type
Static members must be declared:
Inside class only
Outside class only
Inside and defined outside
None
Which keyword is used for static variable?
static
const
global
friend
Static members are initialized:
Once per program
For each object
For each function call
None
If a class has 3 objects and 1 static variable, how many copies of static exist?
1
3
0
Infinite
Static function can be called using:
Object only
Class name only
Both object & class name
None
Friend function allows access to:
Only public
Only protected
All private/protected/public
None
Friend function is declared using:
static
friend
inline
extern
Friend function is:
Member of class
Non-member but has access
Always static
Virtual
Overloading member function means:
Same name, diff params
Same return type only
Different classes
None
Array of objects is:
Collection of objects
Collection of classes
Pointer to class
None
Passing object as parameter uses:
Value/Reference
Only value
Only pointer
None
Returning object from function is:
Allowed
Not allowed
Only reference
None
Nested class is:
Returning object from function is:
Allowed
Not allowed
Only reference
None
Nested class is:
Class within class
Derived class
Static class
None
Constructor has:
No return type
int return type
void return type
Any return type
Destructor is prefixed with:
~
!
?
None
Friend function allows access to:
Only public
Only protected
All private/protected/public
None
Friend function is declared using:
static
friend
inline
extern
Friend function is:
Member of class
Non-member but has access
Always static
Virtual
Overloading member function means:
Same name, diff params
Same return type only
Different classes
None
Array of objects is:
Collection of objects
Collection of classes
Pointer to class
None
Passing object as parameter uses:
Value/Reference
Only value
Only pointer
None
What is the default access specifier for class members in C++?
public
private
protected
None
Which of the following statements is true about destructors?
They cannot be overloaded
They are called automatically when an object goes out of scope
They can take parameters
They must have the same name as the class
