Menu
Topics Index
...
`

Methods Output501


If you need explanation Read this topic

If you need Answer Take test on this topic

Methods Output501
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 = sum(a, b);
        System.out.println("c = " + c);
    }
    
    public static int sum(int b, int a)
    {
        System.out.println("a = " + a + " b = " + b);
        return a + b;
    }
}

A. a = 34 b = 56
c = 90
B. a = 56 b = 34
c = 90
C. c = 90
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.

a.. here we r using fnctn call here sum is a fnctn n values r passed into it thru call by value method in wich a copy of actual argmnt is snt to called fnctn. here a n b r two variables ..sum is a retrn typ fnctn.. sum() is calld in main fnctn n value of a n b r sent as argmnts in sum() ...in sum() defntn... we hv sum(int b,int a) so the values of a passd in main is taken as b value in sum() and vicr versa i.e in sum() b=36 and a=54 hence these r prntd in sop...now sum() is retrnng a b i.e c=90 wich is prntd in main

Posted by Asma Mujtaba Khan    2014-12-01 08:49:17


And B. Here we called method sum with passed parameters a=34,b=56 But in the called method the values were a=56,b=34, then it is going to print a and b values and the method returns int value 90. Then the C value is 90.

Posted by Damu Surya    2014-12-01 09:31:46


This dose is now closed and the winners are Damodar Ukkadala,  for 'First Correct Comment', Sai Ram,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Asma Mujtaba Khan. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-02 03:56:09


© meritcampus 2019

All Rights Reserved.

Open In App