Menu
Question Index
...

What will be the output of the following program?

class Output
{
    public static void main(String args[])
    {
        Output O = new Output();
        int b = 5;
        O.string(b);
    }
    
    int string(int b)
    {
        /* int b = 5; */

        int a = b;
        int c = a * b;
        int d = c + a;
        int e = a + c * b;

        System.out.println(a + ", " + b + ", " + c + ", " + d + ", " + e);

        OutPut1 t = new OutPut1();
        System.out.println(t.a + ", " + t.b + ", " + t.c + ", " + t.d + ", " + t.e);

        OutPut1 t2 = fix(t);
        
        OutPut1 t3 = new OutPut1();
        System.out.println(t.a + ", " + t2.e);
    }
    
    OutPut1 fix(OutPut1 sum)
    {
        sum.b = sum.a + sum.b + sum.c + sum.d + sum.e;
        return sum ;
    }
}

class OutPut1
{
    int a = 5;
    int b = a;
    int c = a + b;
    int d = a + b * c;
    int e = d + c * a;
}


5, 5, 25, 30, 130
5, 5, 10, 55, 105
5, 105
5, 5, 25, 30, 150
5, 5, 10, 100, 550
5, 550
5, 5, 25, 30, 130
5, 5, 10, 55, 105
180, 105
Compilation Error

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App