Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Static method called from a null object reference

807589Nov 10 2008 — edited Nov 10 2008
Hello folks,

Here´s the code:
public class TestClass {
	
	public static void main(String[] args) {
		StaticNull _null_ = null;
		_null_.testNull();
	}

}

class StaticNull {
	
	public static void testNull() {
		System.out.println("testNull");
	}
	
}
I know that a static method belongs to the class, so you don´t need an
instantiated object of that class to call it. But in the code above, as
I'm calling the testNull method from a null reference, shouldn't a NullPointerException
be thrown?

Best regards,

Danniel
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2008
Added on Nov 10 2008
53 comments
671 views