posted 22 years ago
Here's another example of the fact that a null reference can be used to access a static member of a class.
In the above example, there really isn't a lot of difference between accessing the static member as Green.a or g3.a. Even though g3 has a null value, the type is still Green so the compiler knows exactly what class member is being accessed. Similarly, the following would even work.
When accessing a static member, the type of the reference is what is important. The actual value of the reference doesn't make any difference. Static references are resolved at compile time so the run time value of the reference makes no difference.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>