What Is The Use Of Instance Variable In Java?

4 Answers

Scrut Inizer Profile
Scrut Inizer answered
Unlike class variables, instance variables are unique for each instance. Example: You have a class "bike" with the attributes "color" and "make". Whenever you instantiate that class (to create an object), these attributes are used separately in each object so you can create a "red" bike and a "blue" bike. In order to do so, each object has to have its own set of variables. And that set is called instance variable.
Anonymous Profile
Anonymous answered
It determines the state of the object with which the each instance of the class can have its own behaviour and it makes the object independant to each other.
Virgo Nadia Profile
Virgo Nadia answered
The object in a java class is called an instance of that class and if the object contains some variables then it is called as instance variables. The independent module of programming instructions that contains objects is called instance methods. For example, if the Flower class is defined already and now wants to create an object, then object is an instance of the Flower class and the types are instance variables in the object.

It is important to remember for a programmer that the class of an object adopts the types of the instance variables; however, the actual data is including inside the individual objects, not the class. Thus, each object has its own set of data. The applet is an object; the independent module of programming instructions is instance method of the applet.

The source code for the method is in the class, which is used to create the applet. Still, it's better to think of the instance method as be classified to the object, not to the class. The non-static independent module of programming instructions in the class simply identify the instance methods that every object created from the class will contain. Many classes contain only static methods, or only non-static methods. The static methods variables and methods are independent module of programming instructions.

Answer Question