0% found this document useful (0 votes)
49 views

IT1406_2023

vta

Uploaded by

mr.kumaran14
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)
49 views

IT1406_2023

vta

Uploaded by

mr.kumaran14
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/ 12

University of Colombo, Sri Lanka

University of Colombo School of Computing


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

IT1406 — Introduction to Programming


Multiple Choice Question Paper
(2 Hours)

Important Instructions

• The duration of the paper is 2 Hours.

• The medium of instructions and questions is English.

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

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

• Each question will have 5 (five) choices with ONLY ONE correct answer.

• This paper consists of 100 marks and all the questions will carry equal marks.

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

• Note that questions appear on both sides of the paper. If a page or part of 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.

• Any electronic device capable of storing and retrieving text, including electronic dictionaries,
smartwatches, and mobile phones, is not allowed.

• 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 is correct regarding the Java programming language?

a). It derives its syntax from the C language.


b). It is a platform-specific programming language.
c). The output of a Java compiler is an executable code.
d). A Java applet is a small program that executes on the server.
e). Characters of Java are inherited from the Python programming language

2). Which of the following indicates the correct statement regarding the top-down development pro-
cess?

a). Modular design is connected directly to top-down development.


b). Data-driven programming is based on a structured, top-down approach.
c). It starts with low-level modules and progressively forms a high-level system.
d). Testing and debugging are typically delayed until the entire system is implemented.
e). Detailed implementation of individual functions begins without considering the overall
system design.

3). Which of the following statement(s) is/are correct regarding type conversion in Java program-
ming?

(I) Int can be assigned to a byte by casting the target type to a byte.
(II) There are automatic conversions from the numeric types to Boolean.
(III) Automatic type conversion will occur if the destination type is larger than the source type.

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


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

4). Which of the following can be a valid Identifier in Java?

a). class name b). 9className c). class-name


d). className@ e). class name

5). If int a=2 and int b=3 are in a Java program, what would be the values of a&b and a|b
respectively?

a). 1,0 b). 0,1 c). 1,1


d). 2,3 e). 3,2

2
6). Consider the following code written in Java.
1 public class stringOut {
2 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 s ) {
3 S t r i n g s t r = ” Hello −world ! ” ;
4 i n t a = s t r . lastIndexOf ( ”o” ) ;
5 System . o u t . p r i n t l n ( a ) ; } }

Which one of the following indicates the correct output of the above code?

a). 4 b). 5 c). 7


d). 8 e). 9

7). Match each flowchart symbols with the correct description

Test Type Description


A - Represents a decision point
I) -
where a question is asked, and the
flow of the chart follows different
paths based on the answer.

II) – 
B - Represents an input or output
process in an algorithm.

C - Represents the starting or


III) - stopping point in the logic.

a). I →A, II →C, III → B b). I →B, II →C, III →A c). I →C, II →B, III →A
d). I →B, II→A, III →C e). I →C, II →A, III →B

3
8). Which of the following statement(s) is/are correct regarding the repetition control structure?

(I) The DO WHILE loop is an example of a leading decision loop.


(II) The REPEAT. . . UNTIL structure is a trailing decision loop.
(III) Counted repetition occurs when the exact number of loop iterations is known in advance.

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


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

9). Consider the following code written in Java.


1 p u b l i c c l a s s Calc2 {
2 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 s ) {
3 c h a r ch1 = ’ 1 ’ ;
4 ++ ch1 ;
5 System . o u t . p r i n t l n ( ch1 +=3) ; } }

Which one of the following indicates the correct output of the above code?

a). 11111 b). 14 c). 5


d). Compiler error e). Runtime error

10). is used to destroy unused objects and their memory is released for later
reallocation in Java.

a). Memory.release() method b). Delete operator c). Free() method


d). Garbage collection e). Disposal mechanism

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


1 i n t [ ] numbers = { 1 , 2 , 3 , 4 , 5 } ;
2 f o r ( i n t i = 0 ; i < numbers . l e n g t h ; i ++) {
3 numbers [ i ] + = 3 ; }
4 System . o u t . p r i n t l n ( numbers [ 2 ] ) ;

Which one of the following indicates the correct output of the above code segment?

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


d). 5 e). 6

4
12). Consider the following code which is written in Java.
1 p u b l i c c l a s s Sample {
2 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 s ) {
3 i n t x = 15 , y = 4;
4 f l o a t z = ( f l o a t ) ( x / y) * 2;
5 System . o u t . p r i n t ( z ) ; } }

Which one of the following shows the output of the above code?

a). 8 b). 8.0 c). 9


d). 6 e). 6.0

13). Consider the following code written in Java.


1 p u b l i c c l a s s Example {
2 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 s ) {
3 i n t sum = 0 ;
4 f o r ( i n t i = 0 ; i <= 1 0 ; i ++) {
5 i f ( i % 3 == 0 )
6 continue ;
7 sum = sum + i ;
8 i f ( sum > 1 5 ) {
9 break ;}}
10 System . o u t . p r i n t l n ( sum ) ; } }

Which one of the following indicates the correct output of the above code?

a). 15 b). 16 c). 18


d). 19 e). 55

14). Consider the following code written in Java.


1 p u b l i c c l a s s CharApp {
2 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 s ) {
3 i n t a = 7;
4 i n t b = 2;
5 a %= 5 ;
6 a = ( a>b ) ? 1 : 0 ;
7 System . o u t . p r i n t l n ( a ) ; } }

Which one of the following indicates the correct output of the above code?

a). 0 b). 1 c). 2


d). 5 e). 7

5
15). Consider the following code written in Java.
1 public c l a s s SimpleCalc {
2 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 s ) {
3 i n t a = 1;
4 switch ( a ) {
5 case 2:
6 System . o u t . p r i n t ( ”A ” ) ;
7 break ;
8 case 1:
9 System . o u t . p r i n t ( ”B ” ) ;
10 default :
11 System . o u t . p r i n t ( ”C ” ) ; } } }

Which one of the following indicates the correct output of the above code?

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


d). B C e). Compiler error

16). Consider the following code segment written in Java.


1 byte b = 42;
2 char c = ’a ’ ;
3 double d = 100.1234;
4 (A) r e s u l t = ( c* b ) ;
5 System . o u t . p r i n t l n ( ( c * b ) ) ;

Which should be the most suitable data type for (A)?

a). byte b). char c). int


d). short e). long

17). Which of the following is NOT a basic object-oriented programming concept facilitates in Java?

a). Encapsulation b). Inheritance c). Abstraction


d). Polymorphism e). Functional programming

18). indicates how closely the elements or statements of a module are associ-
ated with each other.

a). Decoupling b). Coupling c). Binding


d). Abstraction e). Cohesion

6
19). Consider the following code piece written in Java.
1 p u b l i c c l a s s CharApp {
2 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 s ) {
3 int [][][] x = {
4 {{1 , 2} , {3 , 4}} ,
5 { { 5 , 6 } , { 7 , 8}}
6 };
7 System . o u t . p r i n t ( x [ 0 ] [ 1 ] [ 0 ] ) ; } }

Which one of the following indicates the correct output of the above code segment?

a). 1 b). 3 c). 4


d). 5 e). 8

20). What is the most suitable response that represents, the ‘this’ Keyword in Java?

a). Refers to an external object in the same package.


b). Represents the return value of a method.
c). Use the inside of any method to refer to the current class.
d). Always a reference to the state on which the method was invoked.
e). Use as a reference to an object of the current ’class’ is permitted.

21). Consider the following two classes defined in Java.


1 c l a s s Car {
2 String color ;
3 void s t a r t ( ) {
4 System . o u t . p r i n t l n ( ” S t a r t i n g t h e c a r . ” ) ; } }
5 public c l a s s CarObject {
6 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 s [ ] ) {
7 Car myCar = new Car ( ) ;
8 myCar . c o l o r = ” B l u e ” ;
9 myCar . s t a r t ( ) ; } }

Which one of the following indicates a method, an object and a state of the above code seg-
ment?

a). method: Car(); object: CarObject; state: ”Blue”


b). method: start(); object: myCar; state: color
c). method: Car(); object: CarObject; state: ”Blue”
d). method: start();object: myCar; state: ”Blue”
e). method: Car();object: myCar; state: color

7
22). To disallow a method from being overridden, can be used as a modifier at
the start of its declaration.

a). void b). abstract c). final


d). protected e). public

23). Which of the following statement(s) is/are correct regarding Method Overloading?

(I) Overloaded methods can have different access modifiers.


(II) Overloading methods require all methods to have the same return type.
(III) It allows a class to have multiple methods with the same name but different parameters.

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


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

24). Which of the following statement(s) is/are correct regarding Encapsulation?

(I) It requires all methods to be declared as static.


(II) It binds together code and the data and restricts outside interference.
(III) It promotes modularity by exposing some of the implementation details.

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


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

25). Consider the following code piece 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 s ) t h r o w s E x c e p t i o n {
2 i n t [ ] numbers = { 1 , 2 , 3 } ;
3 try {
4 i n t r e s u l t = numbers [ 2 ] ;
5 System . o u t . p r i n t ( ”A” ) ;
6 } catch ( Exception e ) {
7 System . o u t . p r i n t ( ”B” ) ;
8 } finally {
9 System . o u t . p r i n t ( ”C” ) ; } }

Which one of the following indicates the correct output of the above code segment?

a). A b). AB c). AC


d). BC e). ABC

8
26). Which one of the following does NOT indicate type wrappers in Java?

a). Character b). Long c). Float


d). boolean e). Integer

27). In Java, the exception type automatically defined for the programs to detect errors like division by
zero is .

a). NullPointerException b). ArithmeticException c). ParseException


d). SocketException e). ClassCastException

28). Which of the following statement(s) is/are correct regarding Strings in Java?

(I) String is a primitive data type in Java.


(II) String represents fixed-length, mutable character sequences.
(III) StringBuffer represents growable and writable character sequences.

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


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

29). Consider the following code segment written in Java.


1 int numerator = 10;
2 int denominator = 0;
3 int r e s u l t = numerator / denominator ;
4 int [ ] numbers = { 1 , 2 , 3 } ;
5 int index = 5;
6 int v a l u e = numbers [ i n d e x ] ;

Which of the following exceptions type(s) needed to be checked in the above code?

(I) NullPointerException
(II) ArrayIndexOutOfBoundsException
(III) ArithmeticException

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


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

9
30). method can be used to extract a single character from a String.

a). getChars( ) b). getBytes( ) c). toCharArray( )


d). charAt( ) e). toString( )

31). Which of the following statement(s) is/are correct regarding the enumeration in Java?

(I) It is a list of named constants.


(II) It can have constructors, methods, and instance variables.
(III) It can be used in classes rather than limiting to a variable.

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


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

32). Select the most suitable options for filling the blanks in the following statements.

(I) X helps to embed supplemental information into a source file .


(II) Y are classes that encapsulate a primitive type within an object.
(III) Z is the process by which a primitive type is automatically encapsulated into its
equivalent type wrapper whenever an object of that type is needed.

a). X - Annotations, Y - Autoboxing, Z - Type wrappers


b). X - Annotations, Y - Type wrappers, Z - Autoboxing
c). X - Autoboxing, Y - Type wrappers, Z - Annotations
d). X - Type wrappers, Y - Autoboxing, Z - Annotations
e). X - Type wrappers, Y - Annotations, Z - Autoboxing

33). Which of the following indicates the correct statements regarding packages in Java?

a). Packages are containers for static classes.


b). When creating new class definitions packages will be automatically added.
c). It is a data storage mechanism that facilitates code reuse.
d). There can be classes not accessible by code outside of that package.
e). Java does not support creating a hierarchy of packages.

10
34). Consider the following two classes defined in Java.
1 c l a s s Shape {
2 v o i d draw ( ) {
3 System . o u t . p r i n t l n ( ” Drawing a s h a p e ” ) ; } }
4 c l a s s C i r c l e e x t e n d s Shape {
5 v o i d draw ( ) {
6 (A)
7 System . o u t . p r i n t l n ( ” Drawing a c i r c l e ” ) ; } }

To access the superclass version of the draw() method, which one of the following lines needs to
be added to the given space(mentioned as (A) )?”

a). Shape.draw(); b). super.draw(); c). Circle.draw();


d). myDrawing.draw(); e). draw.draw();

35). Consider the following code written in Java.


1 p u b l i c c l a s s HelloApp {
2 s t a t i c S t r i n g Sample ( S t r i n g [ ] v a l u e s ) {
3 S t r i n g B u i l d e r r e s u l t = new S t r i n g B u i l d e r ( ) ;
4 f o r ( i n t i = 0 ; i < v a l u e s . l e n g t h ; i += 2 ) {
5 r e s u l t . append ( v a l u e s [ i ] ) ; }
6 return r e s u l t . toString () ;}
7

8 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 s ) {
9 S t r i n g [ ] A = { ”A” , ”B” , ”C” , ”D” , ”E” } ;
10 S t r i n g r e s u l t = Sample (A) ;
11 System . o u t . p r i n t l n ( r e s u l t ) ; } }

Which one of the following is correct regarding the output of the above code?

a). ABCDE b). BD c). ACE


d). CDEFG e). Compiler error

36). Which of the following statement(s) is/are correct regarding Scanner class in Java?

(I) It is used for formatting output in Java applications


(II) It reads formatted input and converts it into its binary form.
(III) It can be used to read input from any source that implements the Readable interface.

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


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

11
37). Which of the following statement(s) is/are correct regarding access modifiers in Java?

(I) Classes or interfaces declared as public can be accessed from any other class.
(II) The protected allows access within its subclasses, and classes within the same package.
(III) The private access modifier restricts the access of a class method only to the class in which
it is declared.

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


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

38). Which of the following statement(s) is/are correct regarding design concepts in Java?

(I) The procedure-driven approach considers the processes of a program.


(II) The data-driven approach to program design is based on the data in a program more on the
processes.
(III) In the procedure-driven approach, the actual structure of the data can be seen before all the
high-level processes are defined.

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


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

39). Which one of the following statement(s) is/are correct regarding multithreaded programming.

a). It supports the main loop/polling mechanism.


b). A thread’s priority can only be set once and cannot change dynamically.
c). Thread-local variables are shared among all threads and have the same value in each.
d). Thread priority in Java is a reliable mechanism to control the order of thread execution.
e). Single-threaded programs must wait for each task to end before starting the next.

40). Which of the following statement(s) is/are correct regarding JAVA Database Connectivity(JDBC)?

(I) It is primarily used for connecting Java applications to NoSQL databases.


(II) JDBC uses SQL (Structured Query Language) for interacting with databases.
(III) JDBC is a database management system that is used to interact with relational databases.

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


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

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

12

You might also like