Local Variable and Instance Variable

Java Software Editions (Core Java or Java SE, Advanced Java or Java EE and Java ME), Java Features, Use of Java Programming, Java Environment setup, Java Syntax and Java Program Structure.
Post Reply
swathi
Posts: 134
Joined: Fri Nov 23, 2018 2:52 am

Local Variable and Instance Variable

Post by swathi » Thu Nov 29, 2018 6:04 am

What is meant by Local variable and Instance variable?

kishore
Posts: 55
Joined: Thu Jan 03, 2019 3:57 am

Re: Local Variable and Instance Variable

Post by kishore » Sat Jan 05, 2019 4:36 am

Local Variables:
============
-->A variable defined within a block or method or constructor is called local variable.
-->These variable are created when the block in entered or the function is called and destroyed after exiting from the block or when the call returns from the function.
-->The scope of these variables exists only within the block in which the variable is declared.
i.e. we can access these variables only within that block.


Instance Variables:
==============
--> Instance variables are non-static variables and are declared in a class outside any method, constructor or block.
-->As instance variables are declared in a class, these variables are created when an object of the class is created and destroyed when the object is destroyed.
-->Unlike local variables, we may use access specifiers for instance variables.
-->If we do not specify any access specifier then the default access specifier will be used.

ranu
Posts: 1
Joined: Thu Dec 13, 2018 6:56 am

Re: Local Variable and Instance Variable

Post by ranu » Wed Jan 09, 2019 3:27 pm

Local Veriable:
A veriable that is declared inside the method is called local veriable
Instance Veriable:
A veriable that is declared inside the class but outside the method is called instance veriable.
Static Veriable:
A veriable that is declared as statc is called static veriable.

Post Reply

Return to “Java Programming Fundamentals”