arrow
arrow
arrow
What is the purpose of the final keyword in C++?
Question



What is the purpose of the final keyword in C++?

A.

To restrict inheritance of a class or method

B.

To declare a variable as constant

C.

To allocate memory dynamically

D.

To define a destructor

E.

To make a method virtual

Correct option is A

The final keyword in C++ is used to restrict inheritance or method overriding. When applied to a class, it prevents the class from being inherited. When applied to a method, it prevents the method from being overridden in derived classes.
Important Key Points:
1. Class-level restriction: Declaring a class as final ensures that no other class can inherit from it. Example:
class Base final {};
2. Method-level restriction: Declaring a method as final ensures it cannot be overridden in a derived class. Example:

3. This is primarily used to enforce stricter design constraints and avoid unintended modifications through inheritance.
Knowledge Booster:
· To declare a variable as constant: Use the const keyword, not final. Example: const int a = 10;
· To allocate memory dynamically: Use the new keyword, not final. Example: int* p = new int;
· To define a destructor: Use ~ClassName(), not final. Example:
class Base { ~Base() {}; };
· To make a method virtual: Use the virtual keyword. Example: virtual void display();

Free Tests

Free
Must Attempt
Video Solutions

RBI Assistant Pre 2026 Full Mock Test -01

languageIcon English
  • pdpQsnIcon100 Questions
  • pdpsheetsIcon100 Marks
  • timerIcon60 Mins
languageIcon English
Free
Must Attempt
Video Solutions

RBI Asst Prelims 2026 : Reasoning Section Test 01

languageIcon English
  • pdpQsnIcon35 Questions
  • pdpsheetsIcon35 Marks
  • timerIcon20 Mins
languageIcon English
Free
Must Attempt
Video Solutions

RBI Asst Prelims 2026 : Quant Section Test 01

languageIcon English
  • pdpQsnIcon35 Questions
  • pdpsheetsIcon35 Marks
  • timerIcon20 Mins
languageIcon English
test-prime-package

Access ‘SEBI Grade-A Assistant Manager’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
368k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow