Java Quiz

0 votes, 0 avg
372

Java Questions

1 / 15

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

            }

        }

2 / 15

2. Which of these is not a correct statement?

3 / 15

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

4 / 15

4. How is Date stored in database?

5 / 15

5. Which of these is an incorrect array declaration?

6 / 15

6. What is the function of javap command?

7 / 15

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

8 / 15

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

9 / 15

9. Which environment variable is used to set the java path?

10 / 15

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

11 / 15

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

            }

        }

12 / 15

12. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?

13 / 15

13. Which of the following is not an OOPS concept in Java?

14 / 15

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

        class Output 

        {

            public static void main(String args[])

            {

                int arr[] = {1, 2, 3, 4, 5};

                for ( int i = 0; i < arr.length - 2; ++i)

                    System.out.println(arr[i] + " ");

            } 

        }

15 / 15

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

Your score is

The average score is 36%

0%