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

}

}

Output:

Y = 10

X = 20

Ans = 200

 

Video available on YouTube:


[sbscrbr_form]

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


 

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

852total visits,1visits today


mayank

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

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint