Java Interfaces and Packages Mcqs

Our collections of Multiple choice questions and answers focuses on study of Java Interfaces and Packages. These questions are chosen from a collection of most authoritative and best reference books on Java. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Interfaces and Packages topic comprehensively.

3.
Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?

Public

Protected

No Modifier

All of the mentioned

4.
Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?

Public

Protected

Private

No Modifier

6.
Which of the following is an incorrect statement about packages?

Package defines a namespace in which classes are stored

A package can contain other package within it

Java uses file system directories to store packages

A package can be renamed without renaming the directory in which the classes are stored

8.
What is the output of this program?

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

0

1

2

0 1 2

9.
What is the output of this program?

    package pkg;
    class output 
    {
        public static void main(String args[])
        { 
            StringBuffer s1 = new StringBuffer("Hello");
            s1.setCharAt(1, x);
            System.out.println(s1);
        }
    }

Xello

Xxxxx

Hxllo

Hexlo

10.
What is the output of this program?

    package pkg;
    class output 
    {
        public static void main(String args[])
        {
            StringBuffer s1 = new StringBuffer("Hello World");
            s1.insert(6 , "Good ");
            System.out.println(s1);
        }
   }

HelloGoodWorld

HellGoodoWorld

Compilation error

Runtime error

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

Class manager extends salary {}

Class manager implements salary {}

Class manager imports salary {}

None of the mentioned

15.
What is the output of this 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);
        }
    }

0

2

4

None of the mentioned

16.
What is the output of this 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);
        }
    }

0 0

2 2

4 1

1 4

0Shares
0
Scroll to Top