My Report

Java Interface Test – 1


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. Which of the following is an incorrect statement about packages?

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

 
interface calculate 
{
            int VAR = 0;
            void cal(int item);
}
        class display implements calculate 
        {
            int x;
          public  void cal(int item)
          {
                if (item<2)
                    x = VAR;
                else
                    x = item * item;            
            }
        }
 class interfaces 
{

            public static void main(String args[]) 
            {
                display[] arr=new display[3];
               
               for(int i=0;i<3;i++)
               arr[i]=new display();
               arr[0].cal(0);    
               arr[1].cal(1);
               arr[2].cal(2);
               System.out.print(arr[0].x+" " + arr[1].x + " " + arr[2].x);
            }
}

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

   
    interface calculate
    {
        void cal(int item);
    }
    class displayA implements calculate
    {
        int x;
        public void cal(int item)
        {
            x = item * item;            
        }
    }
    class displayB implements calculate
    {
        int x;
        public void cal(int item)
        {
            x = item / item;            
        }
    }
    class interfaces 
    {
        public static void main(String args[])
        {
            displayA arr1 = new displayA;
            displayB arr2 = new displayB;
            arr1.x = 0;
            arr2.x = 0;      
            arr1.cal(2);
            arr2.cal(2);
            System.out.print(arr1.x + " " + arr2.x);
        }
    }

4. Which of the following is the correct way of implementing an interface salary by class manager?

5. Which of these keywords is used to define interfaces in Java?

6. Which of these keywords is used by a class to use an interface defined previously?

7. Which of these can be used to fully abstract a class from its implementation?

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

   
    interface calculate
    {
        void cal(int item);
    }
    class display implements calculate
    {
        int x;
        public void cal(int item)
        {
            x = item * item;            
        }
    }
    class interfaces
    {
        public static void main(String args[])
        {
            display arr = new display;
            arr.x = 0;      
            arr.cal(2);
            System.out.print(arr.x);
        }
    }

9. Which of these access specifiers can be used for an interface?


 

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.