0% found this document useful (0 votes)
9 views11 pages

It2205 2015

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

It2205 2015

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

UNIVERSITY OF COLOMBO, SRI LANKA

UNIVERSITY OF COLOMBO SCHOOL OF COMPUTING

DEGREE OF BACHELOR OF INFORMATION TECHNOLOGY


Academic Year 2014/2015 – 1st Year Examination – Semester 2

IT2205 - Programming I
25th July, 2015
(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 11 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, correct options which can be considered as key words in
Java.

(a) public (b) static (c) void


(d) main (e) String

2) An interesting feature of Java is its bytecode. Sometimes it is called a computer within a


computer. Select from among the following, correct feature(s) which go(es) well with the
byte code in Java.

(a) Exception Handling (b) Multithreading


(c) Network Programming (d) Publish data in the Internet
(e) Platform Independence

3) Select from among the following, correct statement(s) on Java programming language.

Java is:
(a) case sensitive. (b) strongly typed.
(c) supportive in Internet programming. (d) simple in syntaxes.
(e) a fully object oriented language.

4) Consider the following expression in Java written as a program.

var1=8;

When the program was compiled, there were errors generated. Select from among the following
correct statement(s), which will describe the underlying concept behind the erroneous situation.

(a) Secure programming (b) Case sensitiveness


(c) Strongly typed nature (d) Socket programming.
(e) Auto-boxing

5) Consider the following expression written in a Java program.

final float number = 78.5f;


number = 45.4f;

Select from among the following, incorrect statement(s) regarding the program.

(a) It will generate compile time errors. (b) final is a key word to define constants.
(c) At run time number variable will (d) number is a key word in Java
hold 45.4f.
(e) At run time the program will output
45.4.

6) Select from among the following, data types which can be considered as reference data types.

(a) String (b) int (c) System


(d) Scanner (e) void

2
7) Select from among the following, correct option(s) which illustrate/s String literals in Java.

(a) 7 (b) “Sri Lanka” (c) “N”


(d) ‘C’ (e) “76”

8) Consider the following program written in Java.

public class Ex8{


public static void main(String args[]){
int val;
String str;
boolean flag;
System.out.println(val+" "+str+" "+flag);
}
}

What would the output of the program be?

(a) val+" "+str+" "+flag (b) 0 null false (c) 0 null true
(d) 0 0 0 (e) error

9) Select from among the following, valid variable name(s) which is/are used in Java.

(a) number1 (b) &Mark (c) _value


(d) %Mark (e) 2Number

10) Consider the following program written in Java.

public class Ex10{


public static void main(String args[]){
System.out.println(args[0]+args[1]);
}
}

After compiling successfully, the program was executed by issuing the following command.

java Ex10 4 1

What would the output of the program be?

(a) 5 (b) Ex104 (c) 41


(d) javaEx10 (e) error

11) Consider the following number.

222222222222L

Select from among the following, option(s) which cannot be used to hold the above value as it is.

(a) int (b) long (c) short


(d) byte (e) double

3
Use the following declarations and initializations to evaluate the Java expressions given in
questions 12 - 17. Assume that each expression is evaluated separately in the program.

int value1 = 2;
short num1 = 10;
double num2 = 100;
char ch = 'A'; // note that the ASCII value of A is 65

Select from among the given options, the correct output for each of the questions 12 – 17.

12) System.out.println(value1*(num1+num2));

(a) 2.0 (b) true (c) 220.0


(d) 200 (e) error

13) System.out.println(ch>value1);

(a) 2.0 (b) true (c) 220.0


(d) 63 (e) error

14) System.out.println(ch < ++ch);

(a) 66 (b) true (c) 65


(d) 65.0 (e) error

15) System.out.println((int)(ch=ch++));

(a) 66 (b) B (c) 65


(d) A (e) error

16) System.out.println(num1 & value1);

(a) 12 (b) true (c) 65


(d) 2 (e) error

17) System.out.println(num1 & value1 > num2);

(a) 12 (b) true (c) 65


(d) 2 (e) error

18) Consider the following program written in Java.

public class Ex18{


public static void main(String args[]){
for(int i=0;i<5;i++){
if(i==2) break;
System.out.print(i); }}}

What would the output of the program be?

(a) 012345 (b) 01234 (c) 0123


(d) 012 (e) 01

4
19) Consider the following program written in Java.

public class Ex19{


public static void main(String args[]){
int ar[]={51,12,37,4,15,61};
int value=ar[0];
for(int k=1;k<=5;k++){
if(value>ar[k])
value=ar[k];
}
System.out.println(value);
}
}

What would the output of the program be?

(a) 51,12,37,4,15,61 (b) 61 (c) 4


(d) 51123741561 (e) 12

20) Consider the following program written in Java.

public class Ex20{


public static void main(String args[]){
char ar[]={'A','B','C','D','E','F'};//ASCII value of A is 65
int value=0;
for(int k=0;k<=ar.length-1;k++){
value=ar[k];
if(value%2==1)
System.out.print(value);
}
}
}

What would the output of the program be?

(a) 666870 (b) 656769 (c) ACE


(d) BDF (e) error

21) Select from among the following, relevant key words, which describe the object orientation feature
called data hiding.

(a) extends (b) public (c) private


(d) protected (e) access

22) Select from among the following, valid option(s), which can be considered as (a) class (es),
considering a school system.

(a) Manuja Gunasena (b) Teacher (c) Subject


(d) Grade 6A (e) Student

23) Select from among the following, valid option(s), which can be considered as (an) object (s),

5
considering a school system.

(a) Manuja Gunasena (b) Teacher (c) Subject


(d) Grade 6A (e) Student

Consider the following class declaration written in Java to answer questions 24 – 29.

public class Ex21{


public int count1;
private int count2;
private static int count3;
public Ex21(){}
public setCount1(){
count1=count1;
}
public getCount1(){
return count1;
}
public setCount2(){
count2=count2;
}
public getCount2(){
return count2;
}
}

24) Select from among the following, valid instance variable/s written in the program.

(a) count1 (b) count2 (c) count3


(d) Ex21() (e) Ex21

25) When the class was compiled, there were errors generated. The programmer noticed that get
methods were not written correctly. Select from among the following, valid get method signatures
to be introduced in the class declaration.

(a) public Ex21()


(b) public getCount1(int count1)
(c) public int getCount2()
(d) public getCount2(int count2)
(e) public int getCount1()

26) When the class was compiled, there were errors generated. The programmer noticed that set
methods were not written correctly. Select from among the following, valid set method signatures
to be introduced in the class declaration.

(a) public int count1


(b) public int setCount1(int a)
(c) public void setCount2(int count2)
(d) public void setCount1(int count1)
(e) public int setCount2(int b)

27) The programmer has identified another two programming statements causing confusion to read.

6
They are illustrated below.

count1=count1;
count2=count2;

Select from among the following, valid option(s) that can be used to modify the program to
increase the readability of the program.

(a) count1=count2 (b) this.count2=count2 (c) super.count1=count1


(d) this.count1=count1 (e) count1==count2

28) After correcting all the errors and confusions which existed in the Ex21 class, one has written the
following program and compiled.

class DP{
public static void main(String args[]){
Ex21 ob= new Ex21;
count1=21;
System.out.println(count1);
}
}

When the program was Compiled, errors were generated. Select from among the following, correct
option(s) to substitute the programming statement(s) to avoid errors.

Existing Code  Proposed Code


(a) Ex21 ob= new Ex21;  Ex21 ob= new Ex21();
(b) count1=21;  21= ob.count1;
(c) Ex21 ob= new Ex21;  Ex21 ob()= new Ex21;
(d) count1=21;  ob.count1=21;
(e) System.out.println(count1);  System.out.println(ob.count1);

29) Consider the following program written in Java with new programming statements.
class DP{
public static void main(String args[]){
Ex21 ob= new Ex21();
ob.count2=80;
System.out.println(ob.count2);
}
}

When the program was compiled, errors were generated. Select from among the following correct
option(s) to avoid errors generated.

Existing Code  Proposed Code


(a) Ex21 ob= new Ex21();  Ex21 ob= new Ex21(80);
(b) ob.count2=80;  ob.setCount2(80);
(c) Ex21 ob= new Ex21();  Ex21 ob= new Ex21()=80;
(d) ob.count2=80;  ob.setCount2=80;
(e) System.out.println(ob.count2);  System.out.println(ob.getCount2());

30) Consider the following program written in Java.

7
class What{
public void work(int value){
if(value>0){
System.out.print(value+"");
work(value - 1);
}
}
}
class Ex30{
public static void main(String args[]){
What ob= new What();
ob.work(3);
}
}

What would the output of the program be?

(a) 6 (b) 321 (c) 7


(d) 0 (e) error

31) One has created the package having the name MyPack in the following path in windows
environment.
C:\MyPrograms\Java\MyPack

Select from among the following, valid option(s) to be included in the package path in the
CLASSPATH environment variable.

(a) C:\MyPrograms\Java\MyPack (b) C:\MyPrograms (c) C:\MyPrograms\Java


(d) C:/MyPrograms/Java/MyPack (e) C:/MyPrograms

32) Select from among the following, correct option(s) to specify the class path in the command prompt
while interacting with a Java program.

(a) –processorpath (b) –setclasspath (c) –argumentpath


(d) –classpath (e) –bytecodepath

33) Consider the following program written in Java.

public class Ex32{


public static void main(String args[]){
int ar[]=new int[ -3 ];//note that negative three is assigned here
ar[-0]=1;
ar[-1]=7;
ar[-2]=9;
System.out.println(ar[1]);
}
}

When the program is executed an exception is generated. Select from among the following, the
exception that has been generated during the execution of the above program.

(a) ArrayIndexOutOfBound (b) Arithmetic (c) IllegalArgument


(d) NegativeArraySize (e) Security

Consider the following programs written in Java to answer questions 34 – 35.

8
interface MyInterface{
public int value=9;
void walk();
void eat();
}

class MyClass implements MyInterface{


void walk(){
System.out.println("walking");
}
}

34) Select from among the following, valid statement(s) which can be used with the above programs.

(a) class MyClass extends class A // A is a name of a class


(b) class MyClass extends class X, Y //X and Y are names of classes
(c) class MyInterface extends MyClass
(d) interface OurInterface extends MyInterface
(e) interface NewInterface implements OurInterface, MyInterfar

35) When the above programs were compiled, compile time errors were generated. Select from among
the following valid option(s) which can cause the generation of those errors.

(a) System.out.println("walking"); (b) void eat(); (c) void walk();


(d) interface MyInterface (e) public int value=9;

36) Select among the following, valid option(s) that can be considered unchecked exceptions defined in
the java.lang package.

(a) ArrayIndexOutOfBound (b) Arithmetic (c) IllegalArgument


(d) ClassNotFound (e) Security

37) Consider the following program written in Java.

enum Kingdoms {
Kotte, Polonnaruwa, Seethawaka, Kandy, Anuradhapura
}
class Ex34 {
public static void main(String args[])
{
Kingdoms ap;

ap = Kingdoms.valueOf("Kandy");
System.out.println(ap);

}
}

What would the output of the program be?

(a) 3 (b) 4 (c) 5


(d) Kandy (e) error

9
38) Consider the following programming statements written in Java.

Integer obj= new Interger(8);


Obj = 100;

Select from among the following, (a) valid option(s) which describe the Obj = 100; statement
methodically.

(a) boxing (b) autoboxing (c) unboxing


(d) autounboxing (e) enumeration

39) Select from among the following the package in which the Annotation interface is declared.

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


(d) java.util (e) java.awt

40) One can write generalized classes, interfaces or methods referring to the Object class in the Java
API. But that practice lead to programming problems and nowadays programmers use generics to
avoid such problems in a standard manner. Select from among the following, the programming
problem caused when the Object class is used and averted due to the proper usage of generics in
Java.

(a) Encapsulation (b) Casting (c) Modular programming


(d) Platform independency (e) Type safety

41) Consider the following program written in Java.

public class Ex41{


public static void main(String args[]){
String str = "University of Colombo";
System.out.println(indexOf(‘s’));

}
}

What would have been the output of the program when it was executed at the time of paper setting?

(a) 8 (b) 6 (c) 7


(d) 9 (e) error

42) Consider the following program written in Java.

public class Ex41{


public static void main(String args[]){
String str = "Galleface";
System.out.println(str.endsWith("Face"));
}
}

What would the output of the program be?

(a) Galleface (b) true (c) false


(d) GalleFace (e) error

10
43) Select from among the following, valid interfaces defined in the Collection Framework of Java.

(a) Collection (b) SortedSet (c) NavigatableSet


(d) Set (e) Queue

44) Select from among the following, valid method(s), which yield a boolean output related to the
Scanner class.

(a) hasNext() (b) hasNextBoolean() (c) hasNextByte()


(d) nextInt() (e) nextValue()

45) Consider the following program written in Java.

import java.io.*;
class Ex45 {
public static void main(String args[]) throws IOException
{
char c;
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter characters, 'q' to quit.");
do {
c = (char) br.read();
System.out.print(c);
} while(c != 'q');
}
}

When the program was executed the following message was displayed in the command prompt.

Enter characters, 'q' to quit.

Then the following characters were entered in the command prompt.

ABCq

What would the output of the program be?

(a) ABCq (b) ABC (c) abcq


(d) 656667 (e) error

*******

11

You might also like