NEW
Font size
WorksheetsDay 15 Assessment -Encapsulation & Abstraction, Exception-28June
Total questions: 10
Worksheet time: 5mins
What is encapsulation in C++?
Hiding the internal details and showing only the functionality
Creating multiple functions with the same name
Inheriting properties from another class
Allocating memory for objects
How can you achieve encapsulation in C++?
By using classes and access specifiers
By using only global variables
By writing functions outside of classes
By using pointers
Which access specifier restricts access to the members of a class only to functions within the same class?
public
protected
private
static
What is abstraction in C++?
Using derived classes to extend base class functionality
Providing only essential information and hiding the background details
Allocating dynamic memory for objects
Overloading operators to work with user-defined data types
How is abstraction typically implemented in C++?
Through the use of access specifiers
By using abstract classes and interfaces
By allocating memory dynamically
Through the use of global variables
What is the purpose of exception handling in C++?
To write efficient code
To handle runtime errors gracefully
To manage memory allocation
To create multiple threads
Which keyword is used to throw an exception in C++?
catch
throw
try
finally
Which block is used to handle exceptions in C++?
try
catch
finally
throw
What will happen if an exception is thrown but not caught in C++?
The program will terminate abruptly
The exception will be ignored
The program will enter an infinite loop
The exception will be automatically handled by the system
What does the what() member function of the exception class do?
Returns a string describing the error
Terminates the program
Rethrows the exception
Catches the exception
