Menu
Question Index
...

What will be the output of the following program?

public class Island {
    static String i = "hai";
    public static void main(String[] args) {
        Island i2 = new Island();
        Island i3 = new Island();
        Island i4 = new Island();
        i2.i = "hello";
        i3.i = "good";
        i4.i = "evening";
        System.out.print(i2.i+"-");
        System.out.print(i3.i+"-");
        System.out.print(i4.i+"-");
        System.out.println(Island.i);
        i2 = null;
        i3 = null;
        i4 = null;
        System.out.print(i2+"-");
        System.out.print(i3+"-");
        System.out.print(i4);
    }
}


hai-hai-hai-hai
null-null-null
hello-good-evening-hai
null-null-null
evening-evening-evening-evening
null-null-null
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App