A variable is declared of a particular type and we can use it to store values of that type. The name is up to us but it cannot be a reserved keyword.
File: "var1.java"
public class var1
{
public static void main( String args[] )
{
int var1 ;
var1 = 10 ;
System.out.println( "var1 = " + var1 ) ;
}
}
Output:
M-BAT453-LAB23:ajay ccsfcomputers$ java var1
var1 = 10
What is wrong with the following program ?
File: "var2.java"
public class var2
{
public static void main( String args[] )
{
static var1 ;
var1 = 10 ;
System.out.println( "var1 = " + var1 ) ;
}
}