Interviewer And Interviewee Guide

Java Software Engineer Interview Question:

Explain me why doesn't the following code generate a NullPointerException even when the instance is null?

Submitted by: Muhammad
Test t = null;
t.someMethod();

public static void someMethod() {
...
}

There is no need for an instance while invoking a static member or method, since static members belongs to a class rather than an instance.

A null reference may be used to access a class (static) variable without causing an exception.
Submitted by: Muhammad

Read Online Java Software Engineer Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.