You are on page 1of 13

BACHELOR OF INFORMATION TECHNOLOGY (HONS)

MID SEMESTER EXAMINATION

MODULE TITLE : JAVA PROGRAMMING

MODULECODE : BIT 243

DATE: APRIL 2023


TIME: 1 HOUR

THIS QUESTION PAPER CONSISTS OF ONE (1) SECTION:


SECTION A: MULTIPLE CHOICE QUESTIONS (MCQ) (30 Marks)

INSTRUCTION TO CANDIDATES:

1. Answer ALL questions in the answer MCQ Sheet.


2. Write in BLUE or BLACK pen ONLY.
3. Dictionary and electronic devices ARE PROHIBITED in the Examination Hall.
4. No scripts or answer sheets are to be taken out of the Examination Hall.
5. A candidate who is caught cheating in examinations is liable to be expelled from the
University.
6. Removing any pages from answer sheets or question paper will be considered as violating
examination rules & regulations and would be treated as a serious offence.

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 13 printed pages

Page 1
SECTION A (1 X 30 = 30 MARKS)
Select the correct Answer.

1. Which of the following option leads to the portability and security of Java?

a. Bytecode is executed by JVM


b. The applet makes the Java code secure and portable
c. Use of exception handling
d. Dynamic binding between objects

2. What is Java Virtual Machine (JVM)?

a. It is a physical machine and a specification which provides runtime environment for


java bytecode execution.
b. It is an abstract machine and a specification which provides runtime environment for
java bytecode execution.
c. It is a abstract machine and a implementation which provides runtime environment for
java sourcecode compilation.
d. It is a physical machine and an implementation which provides runtime environment for
java source code compilation.

3. What is a Java development kit (JDK)?

a. It is a set of libraries with a Java runtime environment.


b. It is a just development tool.
c. It is a development tool with a Java runtime environment.
d. It is a just runtime environment.

4. A valid identifier in Java language may contain which characters?

a. 0-9
b. A-Z, a-z
c. $, _ (Underscore)
d. All the above

5. Find the output of the given program?

class Test{
public static void main(String[] args) {
String System="Variable";
System.out.println(System);
}
}

a. Variable
b. Compile-time error

Page 2
c. Exception
d. None of these

6. What is the output of the below Java program with WHILE, BREAK and CONTINUE?

public class myt


{
public static void main(String[] args)
{
int cnt=0;
while(true)
{
if(cnt> 4)
break;
if(cnt==0)
{
cnt++;
continue;
}
System.out.print(cnt + ",");
cnt++;
}
}
}
a. 0,1,2,3,4,
b. 1,2,3,4,
c. 1,2,3,4
d. Compiler error

7. What will be the output of the following Java program?

class Numbers
{
public static void main(String args[])
{
int a=20, b=10;
if ((a < b) && (b++ < 25))
{
System.out.println("This is any language logic");
}
System.out.println(b);
}
}

Page 3
a. 10
b. 11
c. 12
d. Compilation Error

8. What will be the output of the following Java program?

class evaluate
{
public static void main(String args[])
{
int a[] = {1,2,3,4,5};
int d[] = a;
int sum = 0;
for (int j = 0; j < 3; ++j)
sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
System.out.println(sum);
}
}

a. 38
b. 39
c. 40
d. 41

9. Which of the following code segments will produce the displayed output?

1
22
333
4444
55555

I. for (int i = 1; i <= 5; i++) {


for (int j = i; j > 0; j--) {
System.out.print(i);
}
System.out.println();
}
II. for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
System.out.print(i);
}
System.out.println();
}

Page 4
III. for (int i = 1; i < 5; i++) {
for (int j = i; j > 0; j--) {
System.out.print(i);
}
System.out.println();
}

IV. for (int i = 1; i < 6; i++) {


for (int j = 0; j < i; j++) {
System.out.println(i);
}
}

a. I
b. II
c. III
d. IV

10. Which of these is an incorrect array declaration?

a. int arr[] = new int[5]


b. int [] arr = new int[5]
c. int arr[] = new int[5]
d. int arr[] = int [5] new

11. What will be the output of the following Java code?

class array_output
{
public static void main(String args[])
{
int array_variable [] = new int[10];
for (int i = 0; i < 10; ++i)
{
array_variable[i] = i;
System.out.print(array_variable[i] + " ");
i++;
}
}
}
a. 0 2 4 6 8
b. 1 3 5 7 9
c. 0 1 2 3 4 5 6 7 8 9
d. 1 2 3 4 5 6 7 8 9 10

Page 5
12. What are the values of var1 and var2 after the following code segment is executed and the
while loop finishes?

class t
{
public static void main(String[] args)
{
int var1 = 0;
int var2 = 2;
while ((var2 != 0) && ((var1 / var2) >= 0))
{
var1 = var1 + 1;
var2 = var2 - 1;
}
System.out.println("Var1="+var1+",Var2="+var2);

}
}
a. var1 = 0, var2 = 2
b. var1 = 1, var2 = 1
c. var1 = 3, var2 = -1
d. var1 = 2, var2 = 0

13. What will be the output of the following Java program?

class box
{
int width;
int height;
int length;
int volume;
void volume(int height, int length, int width)
{
volume = width*height*length;
}
}
class Prameterized_method
{
public static void main(String args[])
{
box obj = new box();obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(3,2,1);
System.out.println(obj.volume);
}

Page 6
}

a. 0
b. 1
c. 6
d. 25

14. What is the output of the below Java program with a final local variable?

public class TestingMethods8


{
int cars = 20;
void change(final int cars)
{
cars = 10;
this.cars = cars;
}
public static void main(String[] args)
{
TestingMethods8 t8 = new TestingMethods8();
t8.change(30);
System.out.println(t8.cars);
}
}

a. 30
b. 20
c. 10
d. Compiler error

15. Which of the following is not an OOPS concept?

a. Encapsulation
b. Polymorphism
c. Exception
d. Abstraction

16. Here TIH() is a

class TIH
{
TIH ( ) { }
}
a. method
b. constructor
c. Both

Page 7
d. None of the above

17. Choose the correct way of creating an object of the below class.

class Table
{
Table()
{
System.out.println("Table Created");
}
}

a. Table t = new Table;


b. Table t = new Table();
c. Table() t = new Table();
d. None of the above

18. Select the correct output for the below code snippet:

class abc
{
int i;
public int a(int x)
{
i=x+1;
System.out.println("Value of i="+i);
return i;
}
}
public class xyz
{
abc obj1,obj2;
public xyz()
{
obj1=new abc();
obj2=obj1;
obj2.a(3);
}
public static void main(String[] args)
{
xyz x=new xyz();
}
}

a. Null pointer exception


b. Print on the console: 'value of i=4'

Page 8
c. Print on the console: 'value of i=3’
d. Print on the console: 'value of i=5’

19. A final class in java is _______. Select the correct answer:

a. A class that cannot be extended


b. A class that cannot be instantiated
c. A class that cannot be an abstracted
d. None of the above

20. What is the process of defining two or more methods within same class that have same
name but different parameters declaration?

a. method overloading
b. method overriding
c. method hiding
d. none of the mentioned

21. Which of these can be overloaded?

a. Methods
b. Constructors
c. Classes and methods
d. Methods and Constructors

22. What will be the output of the following Java code?

class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a , int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;

Page 9
obj.add(6, 7);
System.out.println(obj.x);
}
}

a. 6
b. 7
c. 8
d. 9

23. What is the output of the Java program?

class Counter2
{
static int count=0;
Counter2()
{
count++;
System.out.println(count);
}
public static void main(String args[])
{
Counter2 c1=new Counter2();
Counter2 c2=new Counter2();
Counter2 c3=new Counter2();
}
}
a. 0
0
0
b. 1
1
1
c. 1
2
3
d. Compile error

24. What is the main difference between a WHILE and a DO-WHILE loop in Java?

a. WHILE loop executes the statements inside of it at least once even if the condition is
false.
b. DO-WHILE loop executes the statements inside of it at least once even if the condition
is false.
c. WHILE loop is fast.
d. DO-WHILE loop is fast.

Page 10
25. What is the output of the below Java code with a FOR loop?

public class myt


{
public static void main(String arg[])
{
int i;
for(i=1; i<5; i++);
{
System.out.print(i+",");
}
}
}

a. 1,2,3,4,
b. 1,2,3,5
c. 5,
d. 5

26. What is the output of the below Java program?

int time=50;
do
{
System.out.print(time + ",");
time++;
}while(time < 53);

a. 50,50,50,
b. 50,51,52,
c. 51,52,53,
d. Compiler error

27. What is the output of the below Java program?

class SimpleCalc
{
public int value;
public void calculate()
{
value +=7;
}
}
public class MultiCalc extends SimpleCalc
{
public void calculate()

Page 11
{
value -=3;
}
public void calculate(int multiplier)
{
calculate();
super.calculate();
value *= multiplier;
}
public static void main(String args[])
{
MultiCalc calculator = new MultiCalc();
calculator.calculate(2);
System.out.println("Value is: "+ calculator.value);
}
}

a. Value is: 8
b. Compilation fails
c. Value is : 12
d. Value is : -12

28. What is the output of the below Java program?

class demo
{
int a, b;
demo()
{
a = 10;
b = 20;
}
public void print()
{
System.out.println ("a = " + a + " b = " + b + "n");
}
}
class Test
{
public static void main(String[] args)
{
demo obj1 = new demo();
demo obj2 = obj1;
obj1.a += 1;
obj1.b += 1;
System.out.println ("values of obj1 : ");

Page 12
obj1.print();
System.out.println ("values of obj2 : ");
obj2.print();
}
}

a. Compile error
b. values of obj1:
a = 11 b = 21n
values of obj2:
a = 11 b = 21n
c. values of obj1:
a = 11 b = 21
values of obj2:
a = 10 b = 20
d. values of obj1:
a = 11 b = 20
values of obj2:
a = 10 b = 21

29. Creating an object from a class is also called ____.

a. Initializing
b. Instantiating
c. Interfacing
d. None of the above

30. An interface in Java is like a 100% ____.

a. abstract class
b. public class
c. inner class
d. anonymous class

End of paper.

Page 13

You might also like