Java Quiz

0 votes, 0 avg
444

Java Questions

1 / 15

1. Which of these is necessary condition for automatic type conversion in Java?

2 / 15

2. 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);

            }

        }

3 / 15

3. What will be the output of the following Java code?

        class Output 

        {

            public static void main(String args[])

            {

                 Object obj = new Object();

    	     System.out.print(obj.getclass());

            }

        }

4 / 15

4. Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?

5 / 15

5. How to format date from one form to another?

6 / 15

6. What will be the output of the following Java code?

        class output 

        {

            public static void main(String args[])

            {

                String a = "hello i love java";

                System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));

            }

        }

7 / 15

7. 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);
  }
}

8 / 15

8. Find the output of the following program.

class increment {
public static void main(String args[]) 
            {        
                 int g = 3;
                 System.out.print(++g * 8);
            } 
        }

9 / 15

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

10 / 15

10. Find the output of the following code.

        class bool_operator 

        {

            public static void main(String args[]) 

            {    

                 boolean a = true;

                 boolean b = !true;

                 boolean c = a | b;

     	     boolean d = a & b;

                 boolean e = d ? b : c;

                 System.out.println(d + " " + e);

            } 

        }

11 / 15

11. Which of these method of Object class can clone an object?

12 / 15

12. 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++;

                }

            } 

        }

13 / 15

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

            }

        }

14 / 15

14. 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));

}

}


                            

15 / 15

15. Find the output of the following code.

        class box 

        {

            int width;

            int height;

            int length;

        } 

        class main

        {

            public static void main(String args[]) 

            {        

                 box obj = new box();

                 obj.width = 10;

                 obj.height = 2;

                 obj.length = 10;

                 int y = obj.width * obj.height * obj.length; 

                 System.out.print(y);

            } 

        }

Your score is

The average score is 36%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top