Can we use static variables before initializing it?
class Variable4
{
static double d;
static String s;
public static void main(String[] alt)
{
System.out.println(d);
System.out.println(s);
}
}
/*
Output:- 0.0 null
Explanation:- For static variables, we are not required to perform initialization explicitly
JVM provides default values for static and instance variables.
*/
{
static double d;
static String s;
public static void main(String[] alt)
{
System.out.println(d);
System.out.println(s);
}
}
/*
Output:- 0.0 null
Explanation:- For static variables, we are not required to perform initialization explicitly
JVM provides default values for static and instance variables.
*/
0 comments: