Java Quiz

0 votes, 0 avg
354

Java Questions

1 / 15

1. Find the output of the following code.

        class output 

        {

            public static void main(String args[])

            { 

               StringBuffer s1 = new StringBuffer("Quiz");

               StringBuffer s2 = s1.reverse();

               System.out.println(s2);

            }

        }

2 / 15

2.  Which variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed?

3 / 15

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

4 / 15

4. Which of these is returned by “greater than”, “less than” and “equal to” operators?

5 / 15

5. Which of these is an incorrect array declaration?

6 / 15

6. Which of the following is a superclass of every class in Java?

7 / 15

7. What will be the output of the following Java program?

        class recursion 

        {

            int func (int n) 

            {

                int result;

                result = func (n - 1);

                return result;

            }

        } 

        class Output 

        {

            public static void main(String args[]) 

            {

                recursion obj = new recursion() ;

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

            }

        }

8 / 15

8. What will be the output of the following 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);

            }

        }

9 / 15

9. Find the output of the following code.

        class array_output 

        {

            public static void main(String args[]) 

            {

                int array_variable [] = new int[10];

    	    for (int i = 0; i < 10; ++i) 

                {

                    array_variable[i] = i;

                    System.out.print(array_variable[i] + " ");

                    i++;

                }

            } 

        }

10 / 15

10. Which constructor creates an empty string buffer with the specified capacity as length.

11 / 15

11. What is the value returned by function compareTo() if the invoking string is less than the string compared?

12 / 15

12. Find the output of the following code.

import java.util.Scanner;

class ThisKeyword {
  private int a = 4;
  private int b = 1;

  void getSum(int a, int b) {
    this.a = a;
    this.b = b;
    System.out.println(this.a + this.b);
  }
}

public class Main {
  public static void main(String args[]) {
    ThisKeyword T = new ThisKeyword();
    T.getSum(3, 5);
  }
}

13 / 15

13. Find the output of the following program.

public class Solution{
       public static void main(String[] args){
               int[]  x = {120, 200, 016};
               for(int i = 0; i < x.length; i++){
                        System.out.print(x[i] + “ “);
               }                   
       }
}

14 / 15

14. What will be the output of the following Java code snippet?

    class abc

    {

        public static void main(String args[])

        {

            if(args.length>0)

            System.out.println(args.length);

        }

    }

15 / 15

15. What will be the output of the following 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));

}

}


                            

Your score is

The average score is 36%

0%