Scope and Life time Variable

Scope and Life time Variable – Java Program

This is our last topic of this chapter 2. This topic will give the details of limitation of variable in java program. This is not access control topic. This blog only work on scope and life time limitation of any variables in any java program. For this we will introduce one simple program.

Program in Scope and life time variable:

In this program, x and ans variable declare outside the scope so we can call life time variables because limit of this variable will remain continue till program end. And y is scope variable so limit of this variable will be remain continue till scope end.

Title: Scope and life time variable

class scope1


public static void main(String args[])


int x = 20,ans;      // Life time Variable

{                            // Scope

int y = 10;   // Scope variable

ans = x*y;

System.out.println(“Y = ” + y);        // Output will come


System.out.println(“X = ” + x);

//System.out.println(“Y = ” + y); // Create an error

System.out.println(“Ans = ” + ans);




Y = 10

X = 20

Ans = 200


Video available on YouTube:


If you have problem on this blog, you can directly comment or subscribe on website.


1323total visits,1visits today


Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.