answersLogoWhite

0


Best Answer

Actually, when you declare a variable as 'final' then the value assingned to the variable does not changes throughout the program.

For example,

class d

{

public final int n=10;

}

In this class d, the value of 'n' would be '10' & its value cannot not be altered by any function declared within the class.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

The final keyword is used to prevent overriding virtual functions. It can be applied to a class as a whole, thus preventing the class from being used as a base class, or it can be applied to a virtual function override, thus preventing that function from being overridden.

This can have a significant benefit in terms of performance because we can statically link to final methods rather than dynamically link to them via a virtual table, and thus provide greater opportunities for inline expansion.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the meaning of final keyword in Cplusplus language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What does the final keyword mean in front of a variable a method a class?

When used in a class declaration, the final keyword means the a class can't be subclassed. In other words, no other class can extend (inherit) a final class, and any attempts to do so will give you a compiler error. The final keyword prevents a method from being overridden in a subclass. Final methods are usually placed in classes where you don't want anyone who is extending your code to meddle with a certain piece of functionality. Declaring a variable with the final keyword makes it impossible to reassign a different value to that variable once it has been initialized with an explicit value -


What if a final keyword is applied to a function?

The final keyword in JAVA means that the class can no longer be derived, i.e. it cannot be used as a base class for a new child class.If you declare a method as final, this method cannot be overridden in any of the child class that may extend this class.


What are the usages of keyword final in java?

It's a built-in keyword that defines an entity that cannot be later modified. It can be used in different aspects within your code (like setting a 'final' class, method (function), or variable).


Which variable is use for create for read only variable?

That really depends on the language. Some languages have "constants" separate from "variables"; in Java, for example, the "final" keyword is used to have a variable that can't be changed once it is assigned a value.


What is the purpose of using final keyword with a class declaration?

The final keyword is used in several different contexts as a modifier meaning that what it modifies cannot be changed in some sense. public final class String This means this class will not be subclassed, and informs the compiler that it can perform certain optimizations it otherwise could not. It also provides some benefit in regard to security and thread safety. The compiler will not let you subclass any class that is declared final. You probably won't want or need to declare your own classes final though. You can also declare that methods are final. A method that is declared final cannot be overridden in a subclass. The syntax is simple, just put the keyword final after the access specifier and before the return type like this: public final String convertCurrency() You may also declare fields to be final. This is not the same thing as declaring a method or class to be final. When a field is declared final, it is a constant which will not and cannot change. It can be set once (for instance when the object is constructed, but it cannot be changed after that.) Attempts to change it will generate either a compile-time error or an exception (depending on how sneaky the attempt is). Fields that are both final, static, and public are effectively named constants.

Related questions

How does the final keyword affect the behavior of Object type in Java?

In Java, the final keyword specifies that the object created cannot be further redefined or derived.


Can you make a class final in java?

yes of course... using the final keyword


When do you declare a class as final?

By using the final keyword in the class declaration statement. Ex: public final class Test {...}


What does the final keyword mean in front of a variable a method a class?

When used in a class declaration, the final keyword means the a class can't be subclassed. In other words, no other class can extend (inherit) a final class, and any attempts to do so will give you a compiler error. The final keyword prevents a method from being overridden in a subclass. Final methods are usually placed in classes where you don't want anyone who is extending your code to meddle with a certain piece of functionality. Declaring a variable with the final keyword makes it impossible to reassign a different value to that variable once it has been initialized with an explicit value -


What if a final keyword is applied to a function?

The final keyword in JAVA means that the class can no longer be derived, i.e. it cannot be used as a base class for a new child class.If you declare a method as final, this method cannot be overridden in any of the child class that may extend this class.


Can you declears static in a local variable in a method in java?

we cannot use the staic keyword inside the method... But we can use the final keyword inside the method....


What are the usages of keyword final in java?

It's a built-in keyword that defines an entity that cannot be later modified. It can be used in different aspects within your code (like setting a 'final' class, method (function), or variable).


What happens if a final keyword is applied to identifier?

The final keyword indicates that a variable (identifier) can not change his value. In case the variable refers to a reference variable (an object) the values of variables inside (the object) can change but the reference can be reassigned (to another object).


Which variable is use for create for read only variable?

That really depends on the language. Some languages have "constants" separate from "variables"; in Java, for example, the "final" keyword is used to have a variable that can't be changed once it is assigned a value.


What is mean by Final?

final is a Java keyword. It is used to:> Mark a variable as final which prevents its value from being changed> Mark a class as final to prevent it from being extended> Mark a method as final to avoid it from beingoverridden


What is the purpose of using final keyword with a class declaration?

The final keyword is used in several different contexts as a modifier meaning that what it modifies cannot be changed in some sense. public final class String This means this class will not be subclassed, and informs the compiler that it can perform certain optimizations it otherwise could not. It also provides some benefit in regard to security and thread safety. The compiler will not let you subclass any class that is declared final. You probably won't want or need to declare your own classes final though. You can also declare that methods are final. A method that is declared final cannot be overridden in a subclass. The syntax is simple, just put the keyword final after the access specifier and before the return type like this: public final String convertCurrency() You may also declare fields to be final. This is not the same thing as declaring a method or class to be final. When a field is declared final, it is a constant which will not and cannot change. It can be set once (for instance when the object is constructed, but it cannot be changed after that.) Attempts to change it will generate either a compile-time error or an exception (depending on how sneaky the attempt is). Fields that are both final, static, and public are effectively named constants.


Is unsigned integer constant are available in Java?

yes use the final keyword, normally variables declared final use all capital letters but this is not required final int A = 10;