is there any keyword in c++ like the "final" keyword in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

is there any keyword in c++ like the "final" keyword in java?

3rd Apr 2018, 11:51 AM
Syed Afrid Ali
Syed Afrid Ali - avatar
5 Answers
+ 10
Yeah 'const' In C++ marking a member function const means it may be called on const instances. Java does not have an equivalent to this. E.g.: class Foo { public: void bar(); void foo() const; }; void test(const Foo& i) { i.foo(); //fine i.bar(); //error } In both Java and C++ member variables may be final/const respectively. These need to be given a value by the time an instance of the class is finished being constructed. source and if you want more check: https://stackoverflow.com/questions/4971286/javas-final-vs-cs-const
3rd Apr 2018, 12:01 PM
Baraa AB
Baraa AB - avatar
+ 3
Yes "const"
3rd Apr 2018, 11:54 AM
Bishal Sarang
Bishal Sarang - avatar
+ 3
thanks guyzz
4th Apr 2018, 3:41 AM
Syed Afrid Ali
Syed Afrid Ali - avatar
+ 3
The const keyword in C++ There is also a final keyword in C++ but it does different things.
30th May 2018, 2:41 PM
Maxwell Anderson
Maxwell Anderson - avatar
+ 2
Syed Afrid Ali welcome bro.. good luck 💙
4th Apr 2018, 11:19 AM
Baraa AB
Baraa AB - avatar