What will happen if you attempt to compile and run this code:
class Mountain {
  static String name = "Himalaya";
  static Mountain getMountain() {
    System.out.println("Getting Name ");
    return null;
  public static void main(String[ ] args) {
    System.out.println( getMountain().name );
The compiler replaces the name of the object with the name of the class for all static fields and methods, so at runtime it makes no difference whether the reference was null or not.
That means mountain.name becomes Mountain.name.

Выдаёт как правильный

2017 Nov 30, 8:10:14 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes