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

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Зареєструйся Зараз
або Підпишись на майбутні тести