Technology News, Online Income, Gadgets, Reviews

Technology News, Gadgets and Reviews

Translate

Breaking

Total Pageviews

Thursday, January 19, 2023

Java Instance Variable

    Java Variable 

A variable is a container which holds the value while the java program is executed. A variable is assigned with a data type. and we can't create a single variable without type. 

Variable is a name of memory location. There are three types of variables in java: local, instance and static.

In this tutorial we are going to learn java Instance variable.


   Java Instance Variable 


Instance Variable: A Variable declared inside the class but outside the body of the method or constructor or block is called and instance Variable. It is not declared as static variable , or if the value of  variable valid from object to object. 


Example :  


Class Test {

 int i =10;   // Instance Variable

public static void main(String [] args){

System.out.println(i);  // Compile Time Error 

Test t = new Test();

System.out.println(t.i);  // It Returns 10

 }

    }

No comments:

Post a Comment