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