github

Made bySaurav Hathi

MCQ Test Java: Functions and Recursion

Q1:

In the below java code, which call to sum() method is appropriate?

class Output

{

public static int sum(int ...x)

{

return 0;

}

public static void main(String args[ ])

{

sum(10);

sum(10,20);

sum(10,20,30);

sum(10,20,30,40);

}

}

Tags:
Section:
Core Programming
Options:
Q2:

Which of these is correct about passing an argument by call-by-value process?

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of the following java code?

class San

{

public void m1 (int i,float f)

{

System.out.println(" int float method");

}

public void m1(float f,int i);

{

System.out.println("float int method");

}

public static void main(String[]args)

{

San s=new San();

s.m1(20,20);

}

}

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this java program?

class overload

{

int x;

double y;

void add(int a , int b)

{

x = a + b;

}

void add(double c , double d)

{

y = c + d;

}

overload()

{

this.x = 0;

this.y = 0;

}       

}   

class Overload_methods

{

public static void main(String args[])

{

overload obj = new overload();  

int a = 2;

double b = 3.2;

obj.add(a, a);

obj.add(b, b);

System.out.println(obj.x + " " + obj.y);

}

}

Tags:
Section:
Core Programming
Options:
Q5:

Which of these methods is given parameters via command line arguments?

Tags:
Section:
Core Programming
Options:
Q6:

How many arguments can be passed to main()?

Tags:
Section:
Core Programming
Options:
Q7:

What is recursion in Java?

Tags:
Section:
Core Programming
Options:
Q8:

Which of these data types is used by operating system to manage the recursion in Java?

Tags:
Section:
Core Programming
Options:
Q9:

Which of these will happen if recursive method does not have a base case?

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this java program?

class recursion

{

    int func (int n)

    {

        int result;

        if (n == 1)

            return 1;

        result = func (n - 1);

            return result;

    }

}

class Output

{

    public static void main(String args[])

    {

        recursion obj = new recursion() ;

        System.out.print(obj.func(5));

    }

}

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of this java program?

class recursion

{

    int fact(int n)

    {

        int result;

        if (n == 1)

            return 1;

        result = fact(n - 1) * n;

        return result;

    }

}

class Output

{

    public static void main(String args[])

    {

        recursion obj = new recursion() ;

        System.out.print(obj.fact(6));

    }

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the value of “d” after this line of java code is executed?

double d = Math.round ( 2.5 + Math.random() );

Tags:
Section:
Core Programming
Options:
Q13:

What is the output of this java program?

class Output

{

     public static void main(String args[])

    {

        double x = 2.0; 

        double y = 3.0;

        double z = Math.pow( x, y );

        System.out.print(z);

    }

}

Tags:
Section:
Core Programming
Options:
Q14:

In java, which one of these methods return the smallest whole number greater than or equal to variable X?

Tags:
Section:
Core Programming
Options:
Q15:

What will be the output of this java program?

public class Delta

{

    static boolean foo(char c)

    {

        System.out.print(c);

        return true;

    }

    public static void main( String[] argv )

    {

        int i = 0;

        for (foo('A'); foo('B') && (i < 2); foo('C'))

        {

            i++;

            foo('D');

        }

    }

}

Tags:
Section:
Core Programming
Options: