Java Quiz

0 votes, 0 avg
201

Java Questions

1 / 15

1. Which of the following is a type of polymorphism in Java?

2 / 15

2. 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?

3 / 15

3. Identify the output of the following program.

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

4 / 15

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

5 / 15

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

6 / 15

6. Find the output of the following program.

public class Solution{
       public static void main(String[] args){
                     byte x = 127;
                     x++;
                     x++;
                     System.out.print(x);
       }
}

7 / 15

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

            }

        }

8 / 15

8. Find the output of the following code.

        import java.util.*;

        class Collection_iterators 

        {

            public static void main(String args[]) 

            {

                LinkedList list = new LinkedList();

                list.add(new Integer(2));

                list.add(new Integer(8));

                list.add(new Integer(5));

                list.add(new Integer(1));

                Iterator i = list.iterator();

                Collections.reverse(list);

    	    Collections.sort(list);

                while(i.hasNext())

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

            }

        }

9 / 15

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

        class A 

        {

            int i;

            public void display() 

            {

                System.out.println(i);

            }    

        }    

        class B extends A 

       {

            int j;

            public void display() 

            {

                System.out.println(j);

            } 

        }    

        class Dynamic_dispatch 

       {

            public static void main(String args[])

            {

                B obj2 = new B();

                obj2.i = 1;

                obj2.j = 2;

                A r;

                r = obj2;

                r.display();     

            }

       }

10 / 15

10. How to convert Date object to String?

11 / 15

11. Which of these statements is incorrect about Thread?

12 / 15

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

            }

        }

13 / 15

13. What is true about final class?

14 / 15

14. Which two classes use the Shape class correctly?

A. public class Circle implements Shape 
   {
    private int radius;
   }
B. public abstract class Circle extends Shape 
   {
    private int radius;
   }
C. public class Circle extends Shape 
   {
   private int radius;
   public void draw();
   }
D. public abstract class Circle implements Shape 
   {
    private int radius;
    public void draw();
   }
E. public class Circle extends Shape 
   {
    private int radius;
    public void draw()
    {
     /* code here */
    }
   }
F. public abstract class Circle implements Shape 
   {
     private int radius;
     public void draw() 
     { 
      /* code here */ 
     }
   }

15 / 15

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

Your score is

The average score is 34%

0%