In class Main we create a reference variable a from class A ,we all know that we not able to use the reference a until we assign it an object ( A a = new A (); ) because a currently does not point to any object so we must not use property and methods of A class
public class Main {
public static void main(String[] args) {
A a = null;
a.x=5 ; // fine code in compile time
a.y=10 ; // fine code in compile time
a.show(); // fine code in compile time
}
}
class A {
int x ;
int y ;
public void show (){
System.out.println("show method");
}
}
a is reference variable not object ,so the reference a not allocated in memory so it must not see the variable x ,y and the method show in A class in compile time my question here why reference a see x ,y and show method in the compile time although the reference a not allocated in memory ?