Prev Next

Java / Local Variables

1. Define local variable.

Posted on Apr 1, 2016 by Senthil Kumar.

Local variable also known as block level variable, are identifiers that are declared within a block of code or method. This variable need to be initialized before using it. In the below examples, "i" variable is an example of local variable and it is visible only to the enclosing block. { int i; ...

Read full answer

2. What is the default value of local variables or method variables?

The local or method level variables are not initialized to any default value, neither primitives nor object references.

Read full answer

3. What is inline value in Java?

Inline value represents the literals in a Java program. For example, String str = "Hello", here the string "Hello" is a inline value.

Read full answer

4. Difference between final and effectively final in Java.

The keyword final ensures that the variable is initialized only once and cannot be altered . Reinitializing would issue compilation errors. Any variable that is initialized only once and not marked as final is known as effectively final. This variable when marked final will not issue any compilat...

Read full answer

5. Can a local class access the variables from enclosing block in Java?

Yes. From Java 8, local variables are accessible from local class that are final or effectively final . Prior to Java 8, it allowed only final variables.

Read full answer

6. What is synthetic field in Java?

Synthetic fields are compiler generated fields to hold reference to the inner local class which is required by JVM. Synthetic fields are scoped private.

Read full answer

«
»

Comments & Discussions