Java Questions & Answers – Method overriding

2
Created on By admin

Java Questions & Answers – Method overriding

1 / 10

1. Which of this keyword can be used in a subclass to call the constructor of superclass?

 

2 / 10

2. What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

 

3 / 10

3. Which of these keywords can be used to prevent Method overriding?

 

4 / 10

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

 

5 / 10

5. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”

  1. public interface Status
  2.    {
  3.         /* insert qualifier here */ int MY_VALUE = 10;
  4.    }

6 / 10

6. Which of these is supported by method overriding in Java?

 

7 / 10

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

  1.  class Alligator
  2.  {
  3.   public static void main(String[] args)
  4.    {
  5.    int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
  6.    int [][]y = x;
  7.    System.out.println(y[2][1]);
  8. }
     

8 / 10

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

  1.    final class A
  2.     {
  3.          int i;
  4.     }
  5.     class B extends A
  6.     {
  7.         int j;
  8.         System.out.println(j + " " + i);
  9.     }
  10.     class inheritance
  11.     {
  12.         public static void main(String args[])
  13.         {
  14.             B obj = new B();
  15.             obj.display();
  16.         }
  17.    }

 

9 / 10

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

  1.   class Abc
  2.   {
  3.       public static void main(String[]args)
  4.       {
  5.           String[] elements = { "for", "tea", "too" };
  6.           String first = (elements.length > 0) ? elements[0]: null;
  7.       }
  8.   }

 

10 / 10

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

  1.     class A
  2.     {
  3.         int i;
  4.         public void display()
  5.         {
  6.             System.out.println(i);
  7.         }
  8.     }
  9.     class B extends A
  10.    {
  11.         int j;
  12.         public void display()
  13.         {
  14.             System.out.println(j);
  15.         }
  16.     }
  17.     class Dynamic_dispatch
  18.    {
  19.         public static void main(String args[])
  20.         {
  21.             B obj2 = new B();
  22.             obj2.i = 1;
  23.             obj2.j = 2;
  24.             A r;
  25.             r = obj2;
  26.             r.display();
  27.         }
  28.    }

     

 

Your score is

The average score is 15%

0%

Leave a Reply

Your email address will not be published. Required fields are marked *