How can we access static variable without class name? Static variable are always qualified with class name but in this case i am able to use it without class name. how its possible??
class Student
{
String email;
String name;
long phone;
static String school="jlc";
public static void main(String[] args)
{
Student st= null;
System.out.println(school);//this should be Student.school but its working.
}
}
In below programme after creating student object, variables are already loaded into memory, but i cannot directly access it with out using object reference.but we can do for static.
class Student
{
String email;
String name;
long phone;
static String school="jlc";
public static void main(String[] args)
{
Student st= new Student();
System.out.println(email);
}
}
main
method isstatic
st.email
for example.