Nothing Special   »   [go: up one dir, main page]

2010 Past Paper

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

UNIVERSITY OF COLOMBO, SRI LANKA

UNIVERSITY OF COLOMBO SCHOOL OF COMPUTING

DEGREE OF BACHELOR OF INFORMATION TECHNOLOGY


st
Academic Year 2009 /2010 – 1 Year Examination – Semester 2

IT2204 - Programming I
07th August, 2010
(TWO HOURS)

Important Instructions :

• The duration of the paper is 2 (two) hours.

• The medium of instruction and questions is English.

• The paper has 45 questions and 13 pages.

• All questions are of the MCQ (Multiple Choice Questions) type.

• All questions should be answered.

• Each question will have 5 (five) choices with one or more correct answers.

• All questions will carry equal marks.

• There will be a penalty for incorrect responses to discourage guessing.

• The mark given for a question will vary from 0 (All the incorrect choices are
marked & no correct choices are marked) to +1 (All the correct choices are
marked & no incorrect choices are marked).

• Answers should be marked on the special answer sheet provided.

• Note that questions appear on both sides of the paper.


If a page is not printed, please inform the supervisor immediately.

• Mark the correct choices on the question paper first and then transfer them
to the given answer sheet which will be machine marked. Please
completely read and follow the instructions given on the other side
of the answer sheet before you shade your correct choices.

1
1) Select from among the following, the correct options which can be considered as packages
that come under the Java standard library.

(a) java.lang (b) java.io (c) java.util


(d) java.awt (e) java.swing

2) Consider the following name which is appearing in the home directory of a windows
environment.

jdk1.5.0_01

Select from among the following, the release version number which can be seen in the
above directory name.

(a) jdk (b) 1 (c) 5


(d) 0 (e) 01

3) Select from among the following, the file name/s which can be qualified as (a) Java source
file(s).

(a) class.java (b) Customer.java (c) Customer.class


(d) Employee.java (e) Employee.class

4) Which of the following options is/are correct on valid statements in Java?

(a) for( x>34 ; int a ; a++); (b) float newValue = 35.5;


(c) int value = value + 1; (d) String myFriend = “Vimukthi”;
(e) import java.applet.*;

5) Select from among the following, what can be considered as key words available in Java.

(a) enum (b) return (c) case


(d) args (e) int

6) Consider the following statement.

“A programmer needs to avoid the execution of some codes from the program.”

Select from among the following, the correct operator(s) which is/are valid in Java to achieve the
wish of the programmer.

(a) // (b) % (c) $


(d) if (e) /* /**

2
Use the following declarations and initializations to evaluate the Java expressions given in
questions 7 - 11. Assume that each expression is evaluated separately in the program.
long x = 10,y = 15,z = 20;
int m = 0;
short k = 10;
char ch = 'B' // note that the ASCII value of B is 66

7) System.out.println(m = x);

(a) false (b) 10 (c) 10.0


(d) 100 (e) error

8) System.out.println(k = k * 100);

(a) 10 (b) 1 (c) 100


(d) 1000 (e) error

9) System.out.println(m = ch);

(a) ch (b) m (c) 66


(d) B (e) error

10) System.out.println(x = y % z);

(a) 10 (b) 15 (c) 20


(d) 0 (e) error

11) System.out.println( z = k + ch );

(a) 66 (b) 10 (c) 76


(d) 8 (e) error

Consider the following program written in Java to answer questions 12 – 20.

class A{
private int var1;
private float value1 = 34.5f;
private static value2;

A(c){
value2 = c;
}

public int setVar1(int x){


x = var1;
}

public void getVar1(){


return var1;
}

3
12) When the program was compiling, errors were generated showing the following messages in the
command prompt.

Select from among the following, the programming statement/s which could be the cause/s for the
error generated indicated as the error number 5.

(a) return var1; (b) private float value1 = 34.5f;


(c) A(c) (d) private static value2;
(e) private int var1;

13) In order to correct the error generated, statements in the program can be replaced with new
statements as shown in the following table.

Row Existing statement New statement


number
1 return var1; System.out.println(value2);
2 private float value1 = 34.5f; private float value1;
3 A(c) A(int a)
4 private static value2; private static long value2;
5 private int var1; public int var1;

Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.

(a) 1 only (b) 2 and 3 only


(c) 3 only (d) 4 only
(e) 5 only

4
14) After successfully correcting the error in question number 12, the program was compiled again. The
following message was displayed in the command prompt.

Select from among the following, the programming statement/s which could be the cause/s for the
error generated.

(a) return var1; (b) private float value1 = 34.5f;


(c) A(c) (d) private static value2;
(e) private int var1;

15) In order to correct the error generated in the question number 14, statements in the program can be
replaced with new statements as shown in the following table.

Row Existing statement New statement


number
1 return var1; System.out.println(value2);
2 private float value1 = 34.5f; private float value1;
3 A(c) A(int a)
4 private static value2; private static long value2;
5 private int var1; public int var1;

Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.

(a) 1 only (b) 2 only (c) 3 only


(d) 4 only (e) 4 and 5 only

16) After correcting the erroneous code traced in question number 15, the program was compiled again.
The following message was displayed in the command prompt showing an error.

Select from among the following, the programming statement/s which could be the cause/s for the
error generated indicated as the error number 16.

(a) return var1; (b) public int setVar1(int x)


(c) A(c) (d) x = var1;
(e) private int var1;

5
17) In order to correct the error generated in question number 16, statements in the program can be
replaced with new statements as shown in the following table.

Row Existing statement New statement


number
1 return var1; System.out.println(value2);
2 public int setVar1(int x) public void setVar1(int x)
3 A(c) A(int a)
4 x = var1; x = int var;
5 private int var1; public int var1;

Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.

(a) 1 only (b) 2 and 3 only (c) 3 only


(d) 4 only (e) 4 and 5 only

18) After correcting the erroneous code traced in question number 17, the program was compiled again.
The following message was displayed again in the command prompt indicating an error.

Select from among the following, the programming statement/s which could be the cause/s for the
error generated.

(a) return var1; (b) public int setVar1(int x)


(c) A(c) (d) x = var1;
(e) private int var1;

19) In order to correct the error generated in question number 18, statements in the program can be
replaced with new statements as shown in the following table.

Row Existing statement New statement


number
1 return var1; System.out.println(value2);
2 public int setVar1(int x) public void setVar1(int x)
3 A(c) A(int a)
4 x = var1; x = int var;
5 private int var1; public int var1;

Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.

(a) 1 only (b) 2 only (c) 2 and 3 only


(d) 4 only (e) 4 and 5 only

6
20) After debugging the erroneous situation in question number 19, the program was complied
successfully. But still, one can see a problematic code in the program which can affect the proper
execution of the program. Consider the following situation regarding the existing statement and the
new statement.

Row Existing statement New statement


number
1 return var1; System.out.println(value2);
2 public int setVar1(int x) public void setVar1()
3 A(c) A(int a)
4 x = var1; var1 = x;
5 private int var1; public int var1;

Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.

(a) 1 only (b) 2 only (c) 2 and 3 only


(d) 4 only (e) 4 and 5 only

21) Select from among the following, the valid array declarations that are allowed in Java.

(a) int ar[]= new ar[]; (b) int[] ar= new int[7];
(c) int ar = new int[85] ; (d) int ar[] = new int[];
(e) int ar[45] = new ar[];

22) Consider the following program written in Java.

public class ProblemOne{


public static void main(String args[]){
char ar[][]= {{'v','a','b','c'},
{'x','i','j','k'},
{'z','x','m','y'},
{'l','m','n','u'}};

for(int x=0 ; x<ar.length ; x++){


for(int y=x ; y<x+1 ; y++)
System.out.print(ar[x][y]);
}
}

What would the output be when the program is executed?

(a) vabc (b) vimu (c) cjxl


(d) lmnu (e) ckyu

7
Use the following declarations and initializations to evaluate the Java expressions given in
questions 23 - 24. Assume that each expression is evaluated separately in the program.

byte a = 10;
float y = 5.0f;
int m = 55;

23) System.out.println(a * m % y);

(a) 10 (b) 5.0 (c) error


(d) 50.0 (e) 0.0

24) System.out.println(a>m && y==a/0 ? a*a : y);

(a) false (b) 100 (c) 5.0


(d) true (e) error

25) Consider the following segment of a Java program.

int year = 2004;


if((year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0))

System.out.println( year + " is a leap year");

else

System.out.println( year + " is not a leap year");

What would be the intended output of the program?

(a) year + " is a leap year" (b) year + " is not a leap year"
(c) 2004 + " is a leap year" (d) 2004 is a leap year
(e) 2004 is not a leap year

26) Consider the following segment of a Java program.

int ar[] = new int[]{1,2,3,4,5};

for(int i=0; i < ar.length ; i ++){

if(ar[i] == 3)

break;

else

System.out.print(ar[i]);

What would be the intended output of the program?

(a) 1245 (b) 345 (c) error


(d) 12 (e) 15

8
27) Consider the following segment of a program written in Java.

int num1 = 10;


int num2 = 20;

System.out.print(num1+" "+num2+" ");

num1 = num1 + num2;

num2 = num1 - num2;

num1 = num1 - num2;

System.out.println(num1+" "+num2);

What would be the output of the program if it is executed successfully?

(a) 10 10 10 10 (b) 10 20 10 20 (c) 10 20 20 10


(d) 10 10 20 20 (e) 20 20 20 20

28) Consider the following program written in Java.

public class Problem{


public static void main (String args[]) {

int value = -1;


do {
if (value == -1){
System.out.print("Vimukthi ");
value++;
}
else {
System.out.print("Jayaweera");
System.out.print(" ");
value--;
}
value += 2;
} while (value < 3);
}

What would be the output of the program?

(a) Vimukthi Vimukthi Vimukthi (b) Jayaweera Jayaweera Jayaweera


(c) Vimukthi Jayaweera (d) Vimukthi
(e) Jayaweera Vimukthi

9
29) Consider the following program written in Java.

class WhileDemo {
public static void main(String[] args){
int count = 5;
while (count > 3) {
System.out.print(count);
count--;
}
}
}

What would be the output of the program?

(a) 12345 (b) 54321 (c) 12


(d) 54 (e) 123

Consider the following program written in Java to answer questions 30 – 32,

public class Switch{


public static void main(String args[]){
int number = 4;
switch(number < 7){
case 1 : System.out.println("One");
case 2-5: System.out.println("between two and five");
case 6 : System.out.println("Six");
}
}
}

30) Select from among the following, statement/s which can be seen in the program that can be
considered as not valid in Java.

(a) public class Switch (b) switch(number < 7)


(c) case 2-5: System.out.println("between two (d) case 6 : System.out.println("Six");
and five");
(e) case 1 : System.out.println("One");

31) Select from among the following, the key words which cannot be seen in the program but required
for the completeness of it.

(a) catch (b) return (c) default


(d) while (e) break

32) When the above program was complied, some errors were reported in the command prompt. Select
from among the following, the cause/s for those errors generated. They were generated due to

(a) missing catch key word. (b) missing while key word.
(c) the case 2-5: programming code (d) the public class Switch statement.
(e) the switch(number < 7) code

10
33) Select from among the following, the correct option/s that can be considered as common
characteristics of sub routines and functions.

(a) They are invoked by stating their names together with any required parameters.
(b) Sub routines and functions may call themselves.
(c) They may themselves call other sub-procedures, but may not call the main procedure.
(d) Once they are called, their results are communicated as global data or passed parameters.
(e) When they are invoked, the program control passes to the called sub procedure and
resumes at the first executable statement in that procedure.

34) There are some guiding principles introduced for decomposition of a program into sub procedures
and eliminating duplication of codes is one such a principle. Select from among the following, the
correct statement/s which describe/s the need of eliminating duplication of codes.

(a) It provides the ability for original programmer or others who follow him to be able
to understand the nature of the program
(b) No task should be coded in more than one place in any program.
(c) Divide the project into small self-contained procedures and allocate procedures among the
programmers to develop.
(d) After decomposition each procedure should perform one and only one task.
(e) Process which has already been coded and known to work correctly in one program can be
copied into another program which requires the same functionality.

35) Consider the following statement noting the blank space.

____________________is a program design tool which approximates the format of a programming


language and is therefore easier to be translated into a program.

Select from among the following, the correct option which can be used to fill the blank.

(a) Nassi-Shneidernam diagram (b) Flow charts


(c) Pseudocode (d) Object Oriented Design
(e) Structures Design

36) Select from among the following, the package in which most of the types that make up the
collection framework are stored.

(a) java.lang (b) java.net (c) java.util


(d) java.awt (e) java.math

37) Consider the following programming statements written in Java.

String str1=”Vimukthi”;
String str2+=” likes playing wrestling”;

What would be the content inside the variable str2?

(a) Vimukthi (b) likes playing wrestling


(c) Vimukthi likes playing wrestling (d) error
(e) likes playing Vimukthi wrestling

11
38) Consider the following program written in Java.

class Str{
public static void main(String args[]){
double value1 = 10000;
float value2 = 35.0f;
String str = String.valueOf(value1);
System.out.println(str + value2);
}
}

What would be the output of the program?

(a) error (b) 10000 (c) 35.0


(d) 10035.0 (e) 10000.035.0

39) Consider the following program written in Java.

class Abc{
public static void main(String args[]){
String str1 = "Anuradhapura";
String str2 = "Anuradhapura";
System.out.print(str1.equals(str2));
}
}

What would be the output of the program?

(a) error (b) false (c) true


(d) Anuradhapura (e) Anu

40) Consider the following program written in Java.

class Compare{
public static void main(String args[]){
String str1 = "Sigiriya";
String str2 = "Jaffna";
System.out.print(str1.compareTo(str2));
}
}

What would be the output of the program?

(a) true (b) false (c) error


(d) 9 (e) Sigiriya

41) Select from among the following, key words which have a direct relationship with the object
oriented concept called data hiding.

(a) private (b) protected (c) public


(d) default (e) main

42) Select from among the following, the stream type/s which is/are supported by the java.io package.

(a) logical (b) binary (c) output


(d) character (e) physical

12
43) FilterInputStream class has nine direct subclasses that provide more specialized ways of
transforming data from an input stream. The following statement gives a description to one such
class inherited from the class FilterInputStream.

“It reads data of primitive types from a binary stream.”

Select from among the following, the correct subclass which matches with the above description.

(a) BufferedInputStream (b) DataInputStream


(c) CheckedInputStream (d) CipherInputStream
(e) DigestInputStream

44) Select from among the following, different items of information that can be expected from an
object of type throwable class about an exception.

(a) A message which has been initialized by a constructor denoting the exception
(b) A way to clean up garbage generated at the end of executing a try block
(c) A record for the execution stack at the time the object was created
(d) A message informing a standard exception after rethrowing and object of type throw
(e) A message informing a wrong usage of an input device

45) Consider the following message which can be expected in the command prompt when a program
statement is executed.

Exception in thread "main" java.lang.StringIndexOutOfBoundsException:


String index out of range: 22

Select from among the following, the programming statements which can be cause the generator of
such a message in the command prompt.

(a) String str1 = "University of Colombo"; (b) for(int i=0;i<ar.length;i++)


String str2 = str1.substring(20,22); int sum+=ar[i];
(c) int value = num3 / 0; (d) System.out.println(“ My number “ + no);
(e) float value = 34.99;

*********

13

You might also like