You are on page 1of 2

B.

Tech CSC – IV Sem


Quiz III(26/03/2019)
Time: 50 min. Marks:10 (Weightage:2.5)
Name: Reg No:

Instructions:
- All questions are compulsory
- Attempt the answer on the given sheet
Q1. Assume that you have written three classes and all these classes are currently in java.lang package.
Belatedly, you decided to arrange these classes into three packages, as shown in the table below: [2]
Package Name Class Name
mypackage.master Mprocessor
mypackage.shared Functionalities
mypackage.slave SProcessors

(a) Is there any change required in the each source file to put each class in the right package? If yes,
write the code for each source file.

(b) To follow the directory structure, do you need to create some sub-directories in your
development directory, and put source files in the correct sub-directories? If yes, what
subdirectories will be created and which subdirectory does each source file go in?

Q3. Examine the following code and explain the scope of i_pub, i_pri, i_def variables. [1]
package p1;
class Main
{public int i_pub;
private int i_pub;
int i_def;
Main(){i_pub=10;
i_pub=20;
i_def=30;}}

Q4. Does importing a package imports the sub packages as well? For example, Does importing pkg.p1.*
also import pkg.p1.p11.*? [1]
Q5. What will be the output of the following code, if there is an error, specify the reason for the error:
[6]
(a) package P1; (b) package P1;
class Test public class Test {
{ public static void main(String args[]) Test( ){System.out.println(“HELLO”); } }
{ String s = "Hello BML"; -----------------------------------------
s.toUpperCase(); package P2;
System.out.println(s);}} import P1.Test;
Note : Test.class file is not in directory P1. class Main
{public static void main(String args[])
{Test t = new Test();}}

(c) package pkg; (d) interface Inter


class Test {private int i=10; }
{ int i,j,k; class Test implements Inter
void disp() { public static void main(String args[])
{System.out.println(i + "," + j + "," + { System.out.println(i);
k);} }
} }
class Main
{ public static void main(String args[])
{ Test[] arr=new Test[3];
for(int m=0;m<3;m++)
{arr[m]=new Test();
arr[m].i = m+4;
arr[m].j= arr[m].i + m;
arr[m].k = arr[m].j +m; }
for (int m = 0; m < 3; ++m)
arr[m].disp();}}

(e) interface Inter (f)


{ int m = 10;} interface Inter {
class Test implements Inter void disp( ){System.out.println("Hello BML");}}
{ Test(){ m = 20;} class Test implements Inter
void disp(){System.out.println(m);} {public static void main(String args[])
public static void main(String args[]) {Test ob = new Test();
{Test t = new Test(); ob.disp();}}
t.disp();}}

You might also like