instance variable in java instance variable in java with example instance variable in java definition instance variable in java interface what are instance variable in java what are instance variable in java with example
non static variable in java non static variable in java with example non static variable error in java
why non static variable cannot be referenced from a static method non static variable in static method
Instance or Non static Variable:
Instance
or Non – static variable is without the static keyword means that it is part of
an object or it also called
"instance" and not a part of a class. It is referred to by the name
of the specific object to which the method or variable belongs.
1) Instance variables are those whose
memory space is created each and every time
whenever object is created.
2) Instance variable’s are always used
for storing specific values.
3) Programmatically Instance variable’s
declaration should not preceded by static
keyword.
Syntax:
Datatype v1,v2…..vn;
4) Each and every instance variable must
be accessed w.r.t object name.
Objectname.Instancevariable;
5) Each and every value of instance variable
is not sharable.
The Following Program illustrate the concept of Instance Data
members
Class InstanceDemo
{
int
x=10; // Instance or non – static
public static void main(String args[])
{
{
InstanceDemo obj=new InstanceDemo();
//creation of object or reference for
//Non-static member
System.out.println("this is non static method"+obj.x);
}
}
Analysis:
Above program which illustrate the
concept of Instance variables. For instance
variable's memory will be
created in object or instance and by using that instance
we can access the
instance data members.
No comments:
Post a Comment