No we can't.
It will throw NullPointerException because null is not an object in java. If method is static it will run & if method is non static it will through an NPE.
For Example:-
Above code will print "Hello World..." as myMethod() is static method.
It will throw NullPointerException because null is not an object in java. If method is static it will run & if method is non static it will through an NPE.
null
does not represent some "base" object, it represents a reference which does not point to any object at all.For Example:-
class TestClass {
static void myMethod() {
System.out.println("Hello World...");
}
}
class Test {
public static void main(String[] args) {
TestClass tc = null; tc.myMethod(); }
}
Above code will print "Hello World..." as myMethod() is static method.