A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

1. Which of these keywords is used to define packages in Java?
a. pkg
b. Pkg
c. package
d. Package
View Answer Report Discuss Too Difficult!
Answer: (c).package

2. Which of these is a mechanism for naming and visibility control of a class and its content?
a. Object
b. Packages
c. Interfaces
d. None of the Mentioned.
View Answer Report Discuss Too Difficult!
Answer: (b).Packages

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?
a. Public
b. Protected
c. No Modifier
d. All of the mentioned
View Answer Report Discuss Too Difficult!
Answer: (d).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?
a. Public
b. Protected
c. Private
d. No Modifier
View Answer Report Discuss Too Difficult!
Answer: (a).Public

5. Which of the following is the correct way of importing an entire package ‘pkg’?
a. import pkg.
b. Import pkg.
c. import pkg.*
d. Import pkg.*
View Answer Report Discuss Too Difficult!
Answer: (c).import pkg.*

6. Which of the following is an incorrect statement about packages?
a. Package defines a namespace in which classes are stored
b. A package can contain other package within it
c. Java uses file system directories to store packages
d. A package can be renamed without renaming the directory in which the classes are stored
View Answer Report Discuss Too Difficult!
Answer: (d).A package can be renamed without renaming the directory in which the classes are stored

7. Which of the following package stores all the standard java classes?
a. lang
b. java
c. util
d. java.packages
View Answer Report Discuss Too Difficult!
Answer: (b).java

8. What is the output of this program?

Note : packages.class file is in directory pkg;
    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();
         }
    }
a. 0
b. 1
c. 2
d. 0 1 2
View Answer Report Discuss Too Difficult!
Answer: (c).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);
        }
    }
a. xello
b. xxxxx
c. Hxllo
d. Hexlo
View Answer Report Discuss Too Difficult!
Answer: (c).Hxllo

10. What is the output of this program?

Note : Output.class file is not in directory pkg.
    package pkg;
    class output 
    {
        public static void main(String args[])
        {
            StringBuffer s1 = new StringBuffer("Hello World");
            s1.insert(6 , "Good ");
            System.out.println(s1);
        }
   }
a. HelloGoodWorld
b. HellGoodoWorld
c. Compilation error
d. Runtime error
View Answer Report Discuss Too Difficult!
Answer: (d).Runtime error

Page 1 of 5