Packages

1

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);
        }
   }

Note : Output.class file is not in directory pkg.

A. HelloGoodWorld
B. HellGoodoWorld
C. Compilation error
D. Runtime error

2

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

3

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

Note : packages.class file is in directory pkg;

A. 0
B. 1
C. 2
D. 0 1 2

4

Which of the following package stores all the standard java classes?

A. lang
B. java
C. util
D. java.packages

5

Which of the following is 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.