When calling a static method, the type reference is relevant not the instance so obj.foo() and Test.foo() get resolved to the same thing.
Best Practice: static members should be accessed statically
While it is possible to access static members from a class instance,
it's bad form, and considered by most to be misleading because it
implies to the readers of your code that there's an instance of the
member per class instance.
https://sonarqube.com/coding_rules#rule_key=squid%3AS2209
Recommend to code as this:
public static void main(String args[]) {
Test obj = null;
// ....
System.out.println(Test.foo());
}