Menu
Question Index
...

What will be the output of the following program?

public class Island {
    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();
        i2 = null;
        i3 = null;
        i4 = null;
        System.out.print(i2 + "-");
        System.out.print(i3 + "-");
        System.out.print(i4);
    }
}


hai-hai-hai-
null-null-null
hello-good-evening-
null-null-null
evening-evening-evening-
null-null-null
Compilation Error or Runtime Error

Doubts

Problems

Topic: Class References And Objects In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App