My Report

Java Methods Online Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

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

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

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

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

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

public interface Status
   {
        /* insert qualifier here */ int MY_VALUE = 10;
   }

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

 
  class Abc
  {
      public static void main(String[]args)
      {
          String[] elements = { "for", "tea", "too" };
          String first = (elements.length > 0) ? elements[0]: null;
      }
  }

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

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

 
   final class A 
    {
         int i;
    }    
    class B extends A 
    {
        int j;
        System.out.println(j + " " + i);  
    }    
    class inheritance 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.display();     
        }
   }

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

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

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


 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.