Java Quiz

0 votes, 0 avg
312

Java Questions

1 / 15

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

2 / 15

2. What is an assignment statement?

3 / 15

3. How is Date stored in database?

4 / 15

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

5 / 15

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

6 / 15

6. 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];
}

7 / 15

7. Identify the modifier which cannot be used for constructor.

8 / 15

8. What is an ineterface?

9 / 15

9. What is the default value of String variable?

10 / 15

10. Find the output of the following program.

public class MyFirst {  
 public static void main(String[] args) {  
 MyFirst obj = new MyFirst(n);  
     }  
     static int a = 10;  
     static int n;  
     int b = 5;  
     int c;  
     public MyFirst(int m) {  
           System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m);  
       }  
    // Instance Block  
      {  
         b = 30;  
         n = 20;  
      }   
    // Static Block  
      static   
    {  
              a = 60;  
         }   
     }  

11 / 15

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

            } 

        }

12 / 15

12. What is the function of javap command?

13 / 15

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

14 / 15

14. How to convert Date object to String?

15 / 15

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

        class A 

        {

            public int i;

            protected int j;

        }    

        class B extends A 

        {

            int j;

            void display() 

            {

                super.j = 3;

                System.out.println(i + " " + j);

            }

        }    

        class Output 

        {

            public static void main(String args[])

            {

                B obj = new B();

                obj.i=1;

                obj.j=2;   

                obj.display();     

            }

       }

Your score is

The average score is 36%

0%