Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

In the following Java code, which call to sum() method is appropriate?
class Output
{
public static int sum(int …x)
{
return;
}
static void main(String args[])
{
sum(10);
sum(10,20);
sum(10,20,30);
sum(10,20,30,40);
}
}

In the following Java code, which call to sum() method is appropriate?
class Output
{
public static int sum(int …x)
{
return;
}
static void main(String args[])
{
sum(10);
sum(10,20);
sum(10,20,30);
sum(10,20,30,40);
}
}
a) only sum(10)
b) only sum(10,20)
c) only sum(10) & sum(10,20)
d) all of the mentioned

Answer: d
Explanation: sum is a variable argument method and hence it can take any number as an argument.

Join The Discussion