Menu
Topics Index
...
`

Methods Output499


If you need explanation Read this topic

If you need Answer Take test on this topic

Methods Output499
What will be the output of the following program.
class MethodsTest
{
    public static void main(String s[])
    {
        int a = 34;
        int b = 56;
        int c = 0;
        sum(a, b);
        System.out.println("c = " + c);
    }
    
    public static int sum(int a, int b)
    {
        System.out.println("a = " + a + " b = " + b);
        int c = 0;
        c = a + b;
        System.out.println("c = " + c);
        return c;
    }
}

A. a = 34 b = 56
c = 90
c = 90
B. a = 34 b = 56
c = 90
c = 0
C. a = 34 b = 56
c = 0
c = 0
D. Compilation Error
Topic: Java Methods - Parameter Passing And Scope

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 b..sum is returng value bt we are not recvng so itl wil 0 only

Posted by Uday Kumar    2014-08-13 03:39:08


d.compilation eror..sum is a writtn typ functn bt not retrng any value in main()..i.e in main it behaves as non return stmnt while itvis retrng value

Posted by Asma Mujtaba Khan    2014-08-13 03:47:08


Ans B:first it will print in side method ...here a=34 and b=56 & c=34+56 is 90 will print..after dat it wil come to out of method and will print c value is zero(c=0)

Posted by Ashok Reddi    2014-08-13 03:48:53


b

Posted by Prabhakar Reddy    2014-08-13 05:36:15


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

Posted by Merit Campus    2014-08-14 04:14:25


© meritcampus 2019

All Rights Reserved.

Open In App