answersLogoWhite

0

I think the main reason is because the inner class may "outlive" the method in which it was created. If this happens, then the memory storing those variables would be lost and we would run into problems when trying to access them. If the variables are defined as final, then Java knows that those values will never change and it can move/copy them when the class is created.

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

How do you access final methods from Outer Classes?

The final modifier has nothing to do with access. If your "outer" classes can see the method, they can access them just like any other methods.


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).


Discuss final method and final classes?

a method declared final can not be overridden, and a class declared as final can not be extended by its sub class.


What is a specifier?

a specifier tells the JVM how to treat a particular class,method and variable while executing the program. For example, final classes cannot be extended and final methods cannot be overriden and final variables cannot be changed once declared. Likewise,static methods and variables can be accessed without having to instantiate an object for their class


When do you declare a variable method and a class final?

When There is No Need to Change the Values of the Variables In Entire lifetime of That variables then we must use that Variable as Final Variable.


What access attribute should static final variables have?

It should be public


What is difference in use between interfaces and abstract classes in java?

While neither abstract classes nor interfaces can be instantiated in Java, you can implement methods in abstract classes. Interfaces can only define methods; no code beyond a method header is allowed.


Why do you have only public static final variables in interfaces?

Because of the below reasons:Class implementations can change value of fields if they are not defined as final. Then they would become a part of the implementation. An interface is a pure specification without any implementation, hence they are final to prevent accidental modificationsIf they are static, then they belong to the interface, and not the object, nor the run-time type of the object.An interface provide a way for the client to interact with the object. If variables were not public, the implementing classes would not have access to them.Hence variables in interfaces are public static and final


Why can not define private and protected modifiers for variables in interface?

No. Interface variables are supposed to be public static final. Interfaces, like abstract classes, cannot be instantiated, so all variables in an interface must be static final ones. They are public because usually interfaces are used throughout an application, and this will ensure versatility.


Difference between super and final keyword?

this is a reference to the current classsuper is a reference to the super class of the current class (the class from which this class extends). You can use super.super if you want to access the second level class. (The class your parent class extends) The purpose of having thisand super keywords is to differentiate between methods and variables in classes that may have the same name as that in the parent class. Under such situations if we want to ensure that only the methods from a particular class only gets called we can use this and super.


Explain with an example program the uses of final keywords?

The Final keyword is used to ensure that the methods/variables are not modified/overridden in their child classes. ex: public class A { public void final getName(){ ... } } public class B extends A{ public void getName(){ ... } } While trying to compile class B, there would be compilation errors. Since the method getName in the parent class is final, it cannot be overridden in the child class.


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)

Trending Questions
What is flickering in cathode ray oscilloscope? What is the best type of bridge to make out of spaghetti that holds 2 kg? How can you tell the current in a circuit has changed? Why donors level are near the conduction band and acceptor level near valence band? What kind of relationship can be concluded about the voltage difference across a resistor and the curent flowing through it? Write a program in C language to implement the apriori algorithm? What is postsecondary program? How do you generate an oscillator signal? Which are the various 16-bit registers in Intel 8085? How do i open a java file in Microsoft visual studio using the command prompt i know you would type notepad helloworld period java to open a java program in notepad but how do i do it for MVS? Will having seven liters of petrol in my diesel 2002 Mondeo ruin the engine even though I have diluted it with 46 liters of diesel fuel? Who invented simple machines and when? What are the reasons for drilling oil? What is Efficiency of Binary Search tree operations? Every scientific discovery or design begins in the? What do you mean by visual in .net? Why the floor tiles in an operating theatre are made of a conducting material? What does watt's law states? Why did linnaeus base his system of classification on physical similarities alone as opposed to incuding molecular and genetic similarities? If a gas occupies 3.67L at a pressure of 102.5 kPa what will its volume be at 100.9 Kpa at constant temperature?