Java Quiz

0 votes, 0 avg
12

Java Questions

1 / 15

1. Which mechanism is used when a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed?

2 / 15

2. 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] + “ “);
               }                   
       }
}

3 / 15

3. The concept of multiple inheritances is implemented in Java by

I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.

4 / 15

4. What is the process of defining two or more methods within same class that have same name but different parameters declaration?

5 / 15

5. Choose the appropriate data type for this field: isSwimmer

6 / 15

6. Which of these method of class String is used to remove leading and trailing whitespaces?

7 / 15

7. Which of these statements are incorrect?

8 / 15

8. 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'));

            }

        }

9 / 15

9. What is not the use of “this” keyword in Java?

10 / 15

10. How is Date stored in database?

11 / 15

11. Which statement provides an easy way to dispatch execution to different parts of your code based on the value of an expression?

12 / 15

12. Find the output of the following program.

public class Solution{
       public static void main(String[] args){
                     short x = 10;
                     x =  x * 5;
                     System.out.print(x);
       }
}

13 / 15

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

            } 

        }

14 / 15

14. What is the process of defining a method in terms of itself, that is a method that calls itself?

15 / 15

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

class multidimention_array 
    {
        public static void main(String args[])
        {
            int arr[][] = new int[3][];
            arr[0] = new int[1];
            arr[1] = new int[2];
            arr[2] = new int[3];               
	    int sum = 0;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    arr[i][j] = j + 1;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    sum + = arr[i][j];
	    System.out.print(sum); 	
        } 
    }

Your score is

The average score is 19%

0%