Java Quiz

0 votes, 0 avg
350

Java Questions

1 / 15

1. 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());

            }

        }

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 environment variable is used to set the java path?

4 / 15

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

            }

        }

5 / 15

5. Find the value of A[1] after execution of the following program.

int[] A = {0,2,4,1,3};
for(int i = 0; i < a.length; i++){
    a[i] = a[(a[i] + 3) % a.length];
}

6 / 15

6. Which of these keywords cannot be used for a class which has been declared final?

7 / 15

7. Which of these keywords is used to prevent content of a variable from being modified?

8 / 15

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

}

}


                            

9 / 15

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

10 / 15

10. Which of these keywords are used for the block to be examined for exceptions?

11 / 15

11. What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below?

    public class First_C {  
       public void myMethod()   
        {          System.out.println("Method");  
        }  
        {       System.out.println(" Instance Block");  
        }    
        public void First_C()  
        {       System.out.println("Constructor ");  
        }  
        static {           System.out.println("static block");  
        }       public static void main(String[] args) {       First_C c = new First_C();  
        c.First_C();  
        c.myMethod();  
      }  
    }   

12 / 15

12. Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?

13 / 15

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

14 / 15

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

            } 

        }

15 / 15

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

            }

        }

Your score is

The average score is 36%

0%