Menu
Topics Index
...
`

Static method and variables1796


If you need explanation Read this topic

If you need Answer Take test on this topic

Static method and variables1796
What will be the output of the following program?
public class Vinayak {
    static int laddu = 4;
    final static String TRUTH = "GaneSh iS soO great";
    static String trunk = "";
    static float mouse = 12.0f;
    public static void main(String[] args) {
        ganesh();
        ganesh();
        ganesh();
        ganesh();
        ganesh();
        ganesh();
        System.out.println(trunk);
    }
    public static void ganesh() {
        vignesh(laddu);
        switch (laddu) {
            case 5 * 3 :
            case 18 :
                laddu -= 3;
                break;
            case ((int) mouse) :
                laddu = 2;
                break;
            default :
                laddu = TRUTH.length() - 1;
                break;
            case 2 :
                laddu = 0;
        }
    }
    public static void vignesh(int i) {
        trunk += TRUTH.charAt(i);
    }
}

A. StrOnG
B. Str nG
C. strong
D. Some other output
E. Compilation Error or Runtime Error
Topic: charAt() Method In Java - Java Character Extraction

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 is e:
because constant expression is required in switch case and (int)mouse is not constant expression

Posted by Mânïshå Mùlchåndânï    2014-07-16 13:12:56


ans e.compilatn err
case((int)mouse) err
case expressn must be constant

Posted by Maheshwari Natarajan    2014-07-16 13:13:24


Answer : A
StrOng will get printed as the length of the string is being manipulated and characters at diff location inthe String TRUTH are being accessed

Posted by Deepak Kumar Yadav    2014-07-16 13:13:30


Answer E.
switch case ly accept constant expression.
compilation error

Posted by NagaRaj Nataraj    2014-07-16 13:18:38


answer is E becoz case expresions must be constants only but in case (int)mouse) it is not a constant.

Posted by Vijay Kumar    2014-07-16 13:21:20


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

Posted by Merit Campus    2014-07-17 09:13:07


© meritcampus 2019

All Rights Reserved.

Open In App