Menu
Topics Index
...
`

Array declaration1781


If you need explanation Read this topic

If you need Answer Take test on this topic

Array declaration1781
What will be the output of the following program?
public class Active {
    public static void main(String[] args) {
        if (true) {
            int[] str = {5};
            String i = "" + str[0];
            System.out.print(i);
        }
        System.out.print("-");
        {
            int[] str = {1, 2};
            System.out.print(str[1]);
        }
        System.out.print("-");
        {
            String str = "I like Java Programming Language";
            System.out.print(str);
        }
        System.out.print("-");
        {
            int str = 124;
            System.out.print(str);
        }
    }
}

A. 5-2-I like Java Programming Language-124
B. 5-5-I like Java Programming Language-5
C. Some other output
D. Compilation Error or Runtime Error
Topic: Java Array Initialization

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans A, first  5 is concatinate to the string and then prints as well as all sop's will print without any error.

Posted by Damu Surya    2014-08-27 12:47:19


Ans A bcz
first 5 is concatenated to the str then prints as well as all sop will print
then str[1]=2 is also printed and then '-'
then str="i like progmming language" is printed then '-' then i is printedwith value 124 without any error.

Posted by Pooja Singh    2014-08-27 13:13:54


C ... becoz { ___ } blocks execute first at run time,,,

Posted by Raju VarshnEy    2014-08-27 14:27:03


a

Posted by Zeg Abder    2014-08-27 16:16:13


Congratulations Pooja Singh. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-28 05:27:04


© meritcampus 2019

All Rights Reserved.

Open In App