0% found this document useful (0 votes)
25 views1 page

Instance Variable

types of variables in java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Instance Variable

types of variables in java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Instance variable :

1.the variables which are created out side all the methods constructors and blocks
is called instance variables
2.instance variables gets life only once the object is created
3.instance variables gets created inside heap memory as part of object
4.the no of copies of instance variables is equal to the no of object created
5.it is not mandatory to initialise the instance variables if user does not
provide then compiler automatically provides the default values
6.instance variables gets created once the object is created and it will destroy
once the object is destroyed
7.instance variables can be access directly inside the non-static block but not
inside the static
8.if we want to access inside static then we have use the reference followed by .
operator
9.instance variables can be access directly inside the constructors
10.instance variables can be access through out the class out side the class also

2. Local variables:
1.the variables which are created inside the block ,methods is called local
variables
2.we cant access local variables outside the local scope i.e we cant access the
local variables outside the method and block
3.2 local variables can not have the same name inside the same scope but inside the
different scope can have the same name
4.local variables gets created inside the stack memory
5.local variables gets life as same as methods once the methods get ready to
execute then after completion of method
execution then the local variables gets destroyed
6.local variables can not static
7.local variables must be initialized before we use
8.local variables does not have any default values

3.static variables
1.the variables which are declared with static keyword is called static variables
2.static variables also known as class variables
3.static variables gets created inside the method area or class area
4.static variables always stores the recent modified values once the static
variable is modified then we cant get back the initial values
5.but incase of instance variables we can get back the initial values
6.static variables can created only once at the time of class loading
7.it is not mandatory to initialize static variables if we don't initialize then
compiler will assign with some default values
8.static variables can be access directly inside the static and non static context
with out creating object

You might also like