wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Classes and Objects Quiz

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

Which of the following is the correct way to declare an object of a class `Student`?

a)

Student s1;

b)

Student();

c)

object Student;

d)

s1 Student;

2.

If `class Car{ };`, how many objects are created with `Car c1, c2, c3;`?

a)

1

b)

2

c)

3

d)

0

3.

Objects are instances of a:

a)

Function

b)

Class

c)

Variable

d)

Array

4.

An object is created in:

a)

Runtime only

b)

Compile time only

c)

Both runtime and compile time

d)

Neither

5.

Which keyword is required to declare an object?

a)

object

b)

instance

c)

None, only class name is needed

d)

declare

6.

Multiple objects of the same class share:

a)

Different member functions

b)

Same member functions

c)

Both different and same

d)

None

7.

Which of the following is true about object declaration?

a)

Must use new keyword

b)

May be declared like variables

c)

Must always be initialized

d)

None

8.

If `Employee e1;` is declared inside main, its scope is:

a)

Global

b)

Local to main

c)

Class scope

d)

None

9.

Which of the following is not an access specifier in C++?

a)

public

b)

private

c)

protected

d)

secured

10.

By default, members of a class are:

a)

public

b)

private

c)

protected

d)

static

11.

Which access specifier allows access inside the class only?

a)

public

b)

private

c)

protected

d)

none

12.

Which access specifier allows inheritance but restricts access outside?

a)

public

b)

private

c)

protected

d)

friend

13.

Which access specifier makes members accessible everywhere?

a)

private

b)

protected

c)

public

d)

static

14.

Protected members are accessible in:

a)

Same class only

b)

Derived classes only

c)

Friend functions only

d)

Both same & derived classes

15.

Access specifiers control:

a)

Data hiding

b)

Inheritance mode

c)

Function definition

d)

Compiler optimization

16.

Which of the following access levels has least visibility?

a)

public

b)

private

c)

protected

d)

friend

17.

Can private members be accessed directly outside the class?

a)

Yes

b)

No

c)

Only in static functions

d)

Only in inline functions

18.

Protected members are most useful in:

a)

Encapsulation

b)

Inheritance

c)

Friend functions

d)

Static functions

19.

A member function can be defined:

a)

Inside class

b)

Outside class

c)

Both

d)

None

20.

Member function defined inside a class is:

a)

Inline by default

b)

Static by default

c)

Virtual by default

d)

None

21.

The scope resolution operator `::` is used when:

a)

Defining function outside class

b)

Accessing private members

c)

Declaring objects

d)

None

22.

Defining functions outside class helps in:

a)

Reducing compilation time

b)

Improving readability

c)

Avoiding inlining

d)

All of these

23.

Which keyword is not used for defining a member function?

a)

return_type

b)

class_name::

c)

function_name

d)

object

24.

Member functions inside a class automatically become:

a)

Static

b)

Inline

c)

Friend

d)

Const

25.

Which operator links a function to a class?

a)

->

b)

.

c)

::

d)

:

26.

Inline functions are usually defined:

a)

In header file

b)

In .cpp file

c)

Both

d)

None

27.

Which of the following is not suitable for inline?

a)

Short functions

b)

Recursive functions

c)

Accessor functions

d)

Getters

28.

The compiler may ignore inline request if function is:

a)

Large in size

b)

Recursive

c)

Contains loops

d)

All

29.

Inline functions reduce:

a)

Execution speed

b)

Function call overhead

c)

Memory usage

d)

None

30.

Inline keyword is:

a)

A request, not a command

b)

Mandatory instruction

c)

Compiler directive

d)

None

31.

Static data members of a class are stored in:

a)

Object memory

b)

Class memory

c)

Shared memory

d)

Global memory

32.

Static variables inside a class are initialized:

a)

Inside constructor

b)

Outside class

c)

With object creation

d)

None

33.

Static data members are:

a)

Shared by all objects

b)

Unique per object

c)

Not accessible

d)

Constant only

34.

Static member function can access:

a)

Only static members

b)

Only private members

c)

All members

d)

None

35.

Static functions do not have:

a)

Access to static members

b)

this pointer

c)

Scope resolution

d)

Return type

36.

Static members must be declared:

a)

Inside class only

b)

Outside class only

c)

Inside and defined outside

d)

None

37.

Which keyword is used for static variable?

a)

static

b)

const

c)

global

d)

friend

38.

Static members are initialized:

a)

Once per program

b)

For each object

c)

For each function call

d)

None

39.

If a class has 3 objects and 1 static variable, how many copies of static exist?

a)

1

b)

3

c)

0

d)

Infinite

40.

Static function can be called using:

a)

Object only

b)

Class name only

c)

Both object & class name

d)

None

41.

Friend function allows access to:

a)

Only public

b)

Only protected

c)

All private/protected/public

d)

None

42.

Friend function is declared using:

a)

static

b)

friend

c)

inline

d)

extern

43.

Friend function is:

a)

Member of class

b)

Non-member but has access

c)

Always static

d)

Virtual

44.

Overloading member function means:

a)

Same name, diff params

b)

Same return type only

c)

Different classes

d)

None

45.

Array of objects is:

a)

Collection of objects

b)

Collection of classes

c)

Pointer to class

d)

None

46.

Passing object as parameter uses:

a)

Value/Reference

b)

Only value

c)

Only pointer

d)

None

47.

Returning object from function is:

a)

Allowed

b)

Not allowed

c)

Only reference

d)

None

48.

Nested class is:

4 lines
49.

Returning object from function is:

a)

Allowed

b)

Not allowed

c)

Only reference

d)

None

50.

Nested class is:

a)

Class within class

b)

Derived class

c)

Static class

d)

None

51.

Constructor has:

a)

No return type

b)

int return type

c)

void return type

d)

Any return type

52.

Destructor is prefixed with:

a)

~

b)

!

c)

?

d)

None

53.

Friend function allows access to:

a)

Only public

b)

Only protected

c)

All private/protected/public

d)

None

54.

Friend function is declared using:

a)

static

b)

friend

c)

inline

d)

extern

55.

Friend function is:

a)

Member of class

b)

Non-member but has access

c)

Always static

d)

Virtual

56.

Overloading member function means:

a)

Same name, diff params

b)

Same return type only

c)

Different classes

d)

None

57.

Array of objects is:

a)

Collection of objects

b)

Collection of classes

c)

Pointer to class

d)

None

58.

Passing object as parameter uses:

a)

Value/Reference

b)

Only value

c)

Only pointer

d)

None

59.

What is the default access specifier for class members in C++?

a)

public

b)

private

c)

protected

d)

None

60.

Which of the following statements is true about destructors?

a)

They cannot be overloaded

b)

They are called automatically when an object goes out of scope

c)

They can take parameters

d)

They must have the same name as the class