Java Quiz

0 votes, 0 avg
361

Java Questions

1 / 15

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

2 / 15

2. What is the process of defining a method in terms of itself, that is a method that calls itself?

3 / 15

3. 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 */ 
     }
   }

4 / 15

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

            }

       }

5 / 15

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

            }

       }

6 / 15

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

7 / 15

7. What is the syntax for java main method?

8 / 15

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

            }

        }

9 / 15

9. What is not the use of “this” keyword in Java?

10 / 15

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

11 / 15

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

    class San

    {

     public void m1 (int i,float f)

     {

      System.out.println(" int float method");

     }

     

     public void m1(float f,int i);

      {

      System.out.println("float int method");

      }

     

      public static void main(String[]args)

      {

        San s=new San();

            s.m1(20,20);

      }

    }

12 / 15

12. Find the output of the following code.

        class array_output 

        {

            public static void main(String args[]) 

            {

                int array_variable [] = new int[10];

    	    for (int i = 0; i < 10; ++i) 

                {

                    array_variable[i] = i;

                    System.out.print(array_variable[i] + " ");

                    i++;

                }

            } 

        }

13 / 15

13. Which of these statements are incorrect?

14 / 15

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

            }

       }

15 / 15

15. Identify the output of the following program.

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

Your score is

The average score is 36%

0%