Java Quiz

0 votes, 0 avg
341

Java Questions

1 / 15

1. Identify the output of the following program.

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

2 / 15

2. In Iterator, hasMoreElements() method of Enumeration has been changed to:

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. File class is included in which package?

5 / 15

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

6 / 15

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

            }

        }

7 / 15

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

class Char {
public static void main(String args[]) {
char ch1, ch2;
ch1 = 88; // code for X
ch2 = 'Y';
System.out.print("ch1 and ch2: ");
System.out.println(ch1 + " " + ch2);
}
} 

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 of these statements are incorrect?

10 / 15

10. 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] + " ");

            } 

        }

11 / 15

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

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. Which statement provides an easy way to dispatch execution to different parts of your code based on the value of an expression?

14 / 15

14. Find the output of the following code.

       class overload 

       {

            int x;

     	double y;

            void add(int a , int b) 

            {

                x = a + b;

            }

            void add(double c , double d)

            {

                y = c + d;

            }

            overload() 

            {

                this.x = 0;

                this.y = 0;

            }        

        }    

        class Overload_methods 

        {

            public static void main(String args[])

            {

                overload obj = new overload();   

                int a = 2;

                double b = 3.2;

                obj.add(a, a);

                obj.add(b, b);

                System.out.println(obj.x + " " + obj.y);     

            }

       }

15 / 15

15. What is garbage collection in the context of Java?

Your score is

The average score is 36%

0%