Java Quiz

0 votes, 0 avg
279

Java Questions

1 / 15

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

2 / 15

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

3 / 15

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

4 / 15

4. Which of the following are not java modifiers?

5 / 15

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

6 / 15

6. Identify the output of the following program.

String str = “Hellow”;
System.out.println(str.indexOf(‘t));

7 / 15

7. Which of these can be used to differentiate two or more methods having the same name?

8 / 15

8. Find the output of the following code.

        class leftshift_operator 

        {

            public static void main(String args[]) 

            {        

                 byte x = 64;

                 int i;

                 byte y; 

                 i = x << 2;

                 y = (byte) (x << 2);

                 System.out.print(i + " " + y);

            } 

        }

9 / 15

9. Find the output of the following program.

class output {
public static void main(String args[]) 
            {
                double a, b,c;
                a = 3.0/0;
                b = 0/4.0;
                c=0/0.0;
    	    System.out.println(a);              System.out.println(b);               System.out.println(c);
            } 
        }

10 / 15

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

11 / 15

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

            }

        }

12 / 15

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

13 / 15

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

        class test 

        {

            int a;

            int b;

            void meth(int i , int j) 

            {

                i *= 2;

                j /= 2;

            }          

        }    

        class Output 

        {

            public static void main(String args[])

            {

                test obj = new test();

    	    int a = 10;

                int b = 20;             

                obj.meth(a , b);

                System.out.println(a + " " + b);        

            } 

        }

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 Output 

        {

            public static void main(String args[]) 

            {

                Integer i = new Integer(257);  

                byte x = i.byteValue();

                System.out.print(x);

            }

        }

Your score is

The average score is 36%

0%