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

It1406 2022 2

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

University of Colombo, Sri Lanka

University of Colombo School of Computing


DEGREE OF BACHELOR OF INFORMATION TECHNOLOGY
( EXTERNAL)
Academic Year 2022 — 1st Year Examination — Semester 1

IT1406 — Introduction to Programming


Multiple Choice Question Paper
(Two Hours)

Important Instructions

• The duration of the paper is Two (2) Hours.

• The medium of instructions and questions is English.

• This paper has 40 questions on 11 pages. Answer all questions.

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

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

• All the 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 -1 (All the incorrect choices are marked & no
correct choices are marked) to +1 (All the correct choices are marked & no incorrect choices
are marked). However, the minimum mark per question would be zero.

• 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/invigilator 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.

• Calculators are not allowed.

• All Rights Reserved. This question paper can NOT be used without proper permission from
the University of Colombo School of Computing.
1). Which of the following statement(s) is/are TRUE with respect to the Java programming lan-
guage?

a). It can be considered as a middle level language.


b). It is a typed language.
c). It is suitable to represent real world entities.
d). It needs JDK to run a java program.
e). It runs only in the internet.

2). Which of the following languages can be considered as ancestries of java programming lan-
guage?

a). Python b). php c). C


d). C++ e). FORTRAN

3). Original intention was to create java language is,

a). to compete with C++.


b). to introduce the OOP concepts.
c). to make the internet programming easy.
d). to introduce programming to the general public.
e). to make a platform independent language to be used in various electronic devises.

4). Which of the following can be considered as whitespace characters in java?

a). Space b). Comma c). Tab


d). Newline e). Semicolon

5). Which of the following can be (a) valid Identifier(s) in Java?

a). myName b). 2ndname c). $name


d). name e). my-Name

2
6). Which of the following is/are primitive data type(s) in java?

a). short b). decimal c). byte


d). string e). Object

7). Which of the following variables is/are NOT suitable to define as f loat?

a). Height of a student b). Temperature c). Log value of a number


d). Average mark of a paper e). Value of sin()

8). If, the variable ch is defined as char ch = 66;, what would be the output of the following
line?
1 System . o u t . p r i n t l n (++ ch ) ;

a). 66 b). 67 c). B


d). C e). Compiler error

9). If, the variable ch is defined as char ch = ’\101’;, what would be the output of the follow-
ing line?
1 System . o u t . p r i n t l n ( ch ) ;

a). \101 b). 101 c). 65


d). A e). Compiler error

10). If, the variable x is defined as int x = 017;, what would be the output of the following line?
1 System . o u t . p r i n t l n ( x ) ;

a). 017 b). 17 c). 16


d). 15 e). Compiler error

3
11). Consider the following piece of code written in Java.
1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 i n t x = 10;
3 i f ( x ==10) { i n t y = 1 5 ; }
4 y = 20;
5 System . o u t . p r i n t l n ( y ) ;
6 }

What will be the output of the above program?

a). 10 b). 15 c). 20


d). Compiler error e). Run time error

12). If two data types are compatible, Java will perform the conversion automatically from one type to
the other. Which of the following conversion(s) will automatically occur in java?

a). long to int b). byte to int c). float to double


d). chat to int e). double to int

13). Consider the following piece of code written in Java.


1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 i n t x = 18 , y = 4;
3 double z = x / y ;
4 System . o u t . p r i n t l n ( z ) ;
5 }

What will be the output of the above program?

a). 4 b). 4.0 c). 4.5


d). Compiler error e). Run time error

14). Consider the following piece of code written in Java.


1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 i n t x = 4 , y = 5 , z =5;
3 i f (++ x<y && ++x>z ) { z ++;}
4 }

What would be the values of x and z respectively after executing these lines?

a). 4, 6 b). 5, 5 c). 5, 6


d). 6, 5 e). 6, 6

4
15). Consider the following piece of code written in Java.
1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 i n t x = 2;
3 do { System . o u t . p r i n t l n ( x +=2) ;
4 } w h i l e ( x <3) ;
5 }

What would be the output after executing this program?

a). 2 b). 3 c). 4


d). Print an infinite loop e). Run time error

16). Consider the following piece of code in Java.


1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 double height = 5 . 3 ;
3 c h a r c a t e g o r y = ( h e i g h t > 5 . 3 ) ? ’A ’ : ’B ’ ;
4 System . o u t . p r i n t l n ( c a t e g o r y ) ;
5 }

What would be the output of the above program?

a). A b). B c). NULL


d). Compiler error e). Run time error

17). Consider the following statements regarding the case statement of Java.

I. default case in the switch statement is optional.


II. It is possible to have any number of case statements within a switch.
III. Variable x can be used as the expression in a switch statement when x is defined as float x = 5;.

Which of the above statements is/are TRUE?

a). I only. b). II only. c). I and II only.


d). II and III only. e). All I, II and III.

5
18). What is the output of the following Java program?
1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 i n t x [ ] [ ] = {{1 ,2} , {3 ,4} , {5 ,6}};
3 System . o u t . p r i n t l n ( x [ 1 ] [ 1 ] ) ;
4 }

a). 1 b). 2 c). 3


d). 4 e). 5

19). Which of the following is/are NOT (a) Program Design Methodology(ies)?

a). Test-driven b). Procedure-driven c). Time-driven


d). Data-driven e). Event-driven

20). Following are some of the basic steps you have to follow in the development of a computer pro-
gram.

A. Test the algorithm for correctness.


B. Code the algorithm into a specific programming language.
C. Outline the solution.

What would be the correct order of these steps?

a). A, C, B b). C, A, B c). B, A, C


d). C, B, A e). B, C, A

21). Consider the following piece of code written in Java.


1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 S t r i n g newCode = ” ” ;
3 i n t o f f s e t = 3;
4 newCode = E n c o d e r ( ”ABCD” , o f f s e t ) ;
5 }

What would be the signature of the Encoder() function mentioned above?

a). int Encoder (String s, int x)


b). int Encoder (char c, int x)
c). String Encoder (char c, int x)
d). String Encoder (int x, String s)
e). String Encoder (String s, int x)

6
22). Following are three (3) basic symbols used in flowcharts.

A B C

What are represented by A, B and C respectively?

a). Terminal symbol, Input/output symbol, Process symbol


b). Input/output symbol, Terminal symbol, Process symbol
c). Input/output symbol, Process symbol, Terminal symbol
d). Process symbol, Terminal symbol, Input/output symbol
e). Process symbol, Input/output symbol, Terminal symbol

23). Consider the following three (3) statements regarding the classes in object orientation.

I. Class contains definitions its properties and methods.


II. A class should always represent an existing concrete artifact.
III. Every class belongs to a particular object.
Which of the above statements is/are TRUE?

a). I only. b). II only. c). I and II only.


d). II and III only. e). I, II and III.

24). Which of the following is/are NOT (a) characteristic(s) of an object in object orientation?

a). Behavior b). Iteration c). Identity


d). Encapsulation e). Loops

25). Consider the three (3) statements given below regarding the following line of code written in Java.
1 C i r c l e m y C i r c l e = new C i r c l e ( 8 ) ;

I. There is a class named myCircle.


II. new keyword creates a new object.
III. This line assigned the value 8 to myCircle.

Which of the above statements is/are TRUE?

a). I only. b). II only. c). I and II only.


d). II and III only. e). I, II and III.

7
26). Consider the following piece of code written in Java.
1 p u b l i c c h a r ABC( i n t x ) {
2 <v a r i a b l e type> y ;
3 return y;
4 }

What is the type of the variable y, mentioned as ”variable type”?

a). int b). char c). boolean


d). float e). can not be defined

27). Which of the following is/are true about constructors in Java?

a). Constructors can return a value.


b). Constructors cannot be inherited.
c). Constructors cannot be overloaded.
d). A class can have multiple private constructors
e). A constructor can be called using the ”new” keyword only.

28). Which of the following is/are (an) Object Orientation Concept(s)?

a). Inheritance b). Iteration c). Abstraction


d). Behavior e). Encapsulation

29). Consider the following three (3) statements regarding polymorphism in Java.

I. It allows a class to have multiple methods with the same name but different parameters.
II. It allows a class to be used as an instance of any of its parent classes.
III. It allows a class to inherit from multiple parent classes.

Which of the above statements is/are TRUE?

a). I only. b). II only. c). I and II only.


d). II and III only. e). I, II and III.

30). Which of the following access control(s) is/are allowed to access to methods and variables of a
class by the other classes in the same package?

a). Public b). Protected c). Private


d). Default e). None of the above

8
31). Which of the following is/are true about the static keyword in Java?

a). A static method cannot be overridden.


b). A static field belongs to the object of a class.
c). A non-static method can access static fields of a class.
d). A static method can access non-static fields of a class.
e). A static method can only be called on an instance of a class.

32). Consider the following three (3) statements regarding the purpose of using packages in Java.

I. It is to organize classes and interfaces into a single unit.


II. It is to provide access control for classes and interfaces.
III. It is to ensure that class and variable names are unique.

Which of the above statement(s) is/are TRUE?

a). I only. b). II only. c). I and II only.


d). II and III only. e). All I, II and III.

33). Consider the following three (3) statements regarding the Abstract classes in Java.

I. You can create objects from abstract classes.


II. You can create subclasses from an abstract class.
III. It can contain both abstract and non-abstract methods.

Which of the above statement(s) is/are TRUE?

a). I only. b). II only. c). I and II only.


d). II and III only. e). All I, II and III.

34). What is the correct way to define an enumeration in Java?

a). enum Days {MONDAY, TUESDAY, WEDNESDAY}


b). Enum Days {MONDAY, TUESDAY, WEDNESDAY}
c). Enumeration Days {MONDAY, TUESDAY, WEDNESDAY}
d). enum days {MONDAY, TUESDAY, WEDNESDAY}
e). Enumeration days {MONDAY, TUESDAY, WEDNESDAY}

9
Questions 35 and 36 are based on the following Java programme.

1 p u b l i c s t a t i c v o i d main ( S t r i n g s [ ] ) {
2 i n t num1 = 0 , num2 = 1 0 , num3 ;
3 try {
4 num3 = num1 / num2 ;
5 System . o u t . p r i n t ( ”A” ) ;
6 }
7 catch ( Exception e ) {
8 System . o u t . p r i n t ( ”B” ) ;
9 }
10 finally {
11 System . o u t . p r i n t ( ”C” ) ;
12 }
13 System . o u t . p r i n t ( ”D” ) ;
14 }

35). What is the output of the above Java program?

a). A b). AC c). ABD


d). ACD e). ABCD

36). What is the output of the above program when num1 = 10 and num2 = 0?

a). B b). ABC c). BCD


d). ABD e). ABCD

37). Consider the following piece of code written in Java.


1 p u b l i c s t a t i c v o i d main ( S t r i n g a r g [ ] ) {
2 i n t x = I n t e g e r . p a r s e I n t ( arg [ 0 ] ) ;
3 char y = arg [ 1 ] . charAt (1) ;
4 System . o u t . p r i n t l n ( x + ”A” + y ) ;
5 }

If the output of this program is 3AB, what would be the valid arguments passed to the pro-
gram?

a). 33 ABC b). 33 CBA c). 3 BAB


d). 3 CBA e). 3 ABC

10
38). Consider the following piece of code written in Java.
1 p u b l i c s t a t i c v o i d main ( S t r i n g a r g [ ] ) {
2 System . o u t . p r i n t l n ( a r g [ 1 ] + a r g [ 2 ] ) ;
3 }

If we pass 1 2 3 as arguments, what will be the output of this program?

a). 3 b). 5 c). 12


d). 23 e). 123

39). What is the use of sleep() method in the Thread class in Java?

a). It causes the current thread to complete execution.


b). It causes the current thread to abort its execution.
c). It causes the current thread to handover its execution to another thread.
d). It causes the current thread to wait for the thread to complete its execution.
e). It causes the current thread to pause for a specified number of milliseconds.

40). Which of the following API is used to establish a connection to a database in Java?

a). JPA b). JMS c). JDBC


d). AJAX e). JAX-RS

————————– *********************** ————————–

11

You might also like