0% found this document useful (0 votes)
12 views7 pages

Understanding Local Variables in Java

The document provides an example of a Java program demonstrating the use of a local variable within the main method. It explains that a local variable is only accessible within its method and shows the output of the program. Additionally, it briefly describes the concept of static methods and instance variables.

Uploaded by

arun kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Understanding Local Variables in Java

The document provides an example of a Java program demonstrating the use of a local variable within the main method. It explains that a local variable is only accessible within its method and shows the output of the program. Additionally, it briefly describes the concept of static methods and instance variables.

Uploaded by

arun kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Local variable:

import [Link].*;

class Localvariable {

public static void main(String[] args)

{
// Declared a Local Variable

int var = 10;

// This variable is local to this main method only

[Link]("Local Variable: " + var);

Output:

Local Variable: 10

static in simple words:


When a method is static, it belongs to the class, not to an object made from the class.

 You can call a static method without creating an object.


(Or)

String[] args in simple words:


 String[] args means "an array of strings called args."
Instance variable:

You might also like