May a null reference be used to access a static variable or method? - ProProfs Discuss
Advertisement

May a null reference be used to access a static variable or method?



Asked by Wyatt Williams, Last updated: Apr 13, 2024

+ Answer
Request
Question menu
Vote up Vote down

3 Answers

Chris Evins

Chris Evins

Want to explore the world.

Chris Evins
Chris Evins, College Student, Schooling, Wolverhampton

Answered Dec 02, 2019

The correct answer to this question is yes, a null reference may be used to access a static variable or method. If used, it will not cause any exceptions. It is not necessary for instances, while static methods or members are being invoked.

This is because static members are home to a class. They do not belong to an instance. In other words, static members share all of the instances in a class, but they do not individually belong to an instance.

This type of question deals with Java, which is a computer programming language. It has been around for over 20 years, debuting in 1995.

upvote downvote
Reply 

John Adney

John Adney

John Adney
John Adney

Answered Jun 17, 2017

The answer is true. Only instance methods or fields need a non-null object reference. Static methods do not even need a reference, but if one exists, it is still independent of all references, even null.
upvote downvote
Reply 

John Smith

John Smith

John Smith
John Smith

Answered Dec 28, 2016

False
upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.