Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
50 views22 pages

Mid Sem

The document provides details about an Object Oriented Programming mid-semester exam to be conducted on 23-10-2021. It includes 3 sections with multiple choice questions - Section 1 has 10 one mark questions, Section 2 has 25 two mark questions, and Section 3 has 5 fill in the blank type questions of 6 marks each. Students are required to answer all questions within the duration of 90 minutes while following the instructions provided.

Uploaded by

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

Mid Sem

The document provides details about an Object Oriented Programming mid-semester exam to be conducted on 23-10-2021. It includes 3 sections with multiple choice questions - Section 1 has 10 one mark questions, Section 2 has 25 two mark questions, and Section 3 has 5 fill in the blank type questions of 6 marks each. Students are required to answer all questions within the duration of 90 minutes while following the instructions provided.

Uploaded by

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

Birla Institute of Technology & Science, Pilani

First Semester 2021-2022

Mid-Semester Exam

Course No. : CS F213


Course Title : Object Oriented Programming
Nature of Exam : Open Book
Weightage : 30% (90 Marks) No. of Pages = 22
Duration : 90 Minutes from 11.00 AM to 12.30 PM.
Date of Exam : 23-10-2021
Note: Please follow all the Instructions given below
1. There are three sections and answer each question of all sections.
2. Assumptions made if any, should be stated clearly at the beginning of your answer.

Section 1: One Mark Questions 1*10 = 10 Marks

1. In Java, automatic conversion takes place when


a) Two types are compatible and the size of the destination type is larger than the size of the
source type.
b) Two types are compatible and the size of the destination type is equal to the size of the
source type.
c) Two types are compatible and the size of the destination type is shorter than the size of
the source type.
d) None

2. How many errors would be generated from the following program?.

a. 2
b. 1
c. 0
d. No errors
3. Bitwise OR operator (|): int x=20, y=14. What is the value of x|y ?.

a. 4
b. 30
c. 0
d. 27

4. What could the output of the following code?.

a. Compiler error
b. Infinity 0.0
c. Infinity 0
d. Infinity NaN

5. Variables declared in a particular method are known as instance variables and can be used
in all methods of the class.
a. True
b. False

6. The JVM performs automatic garbage collection to reclaim the memory occupied by objects
that are no longer used.
a. True
b. False

7. When an object of a subclass is instantiated, a superclass constructor would be called


implicitly or explicitly.
a. True
b. False
8. What could be the output of the below program?.

a. true True
b. false True
c. true False
d. false False

9. Select the suitable option that is not related to string comparison in Java.
a. ==
b. equals()
c. compare()
d. compareTo()

10. If a class is importing any package, then what it is actually importing.


a. Classes and Interfaces
b. Constants
c. Methods
d. None

Section 2: 2 Mark Questions (25*2=50 Marks)


1. What could be the output of the following code?.

a. 20 30 20 200
b. 20 30 20 232
c. 20 30 20 32
d. Compiler error

Ans: d

2. What could be the output of the following program?.

a. f, d are equal but i is not equal


b. f, d and i are equal
c. f and d are not equal
d. Compiler error

3. What could be the output of the following code?.

a. 197
b. Compiler error
c. 131
d. b5

4. What could be the output of the following code?.

a. 100
121
b. 50
129
c. 200
-205
d. 0
154
5. What will be the output of the following code?.
a. 989789
b. 987877
c. 789
d. 789788

6. What could be the output of the following code?.


a. 8 10.4
b. 4 10.4
c. 4 5.2
d. 8 5.2

7. What will be the output of the below code?.

a. YXW
b. XW
c. XWY
d. WXY

8. What could be the output of the following code?.


a. 0 0.0
5 4.5
b. 5 4.5
5 4.5
c. Compiler error
d. 5 0.0
5 4.5

9. What could be the output of the below program?.


a. HELLO
b. world
c. Compiler error
d. None

10. What could be the output of the below code?.

a. A class
B class
C class
b. B class
A class
C class
c. C class
B class
A class
d. Compiler error

11. What could be the output of the following code?.

a. 56
b. 65
c. 57
d. 75

12. Look at the following statements.


A. Abstract classes cannot be instantiated but they can have constructors.
B. Interfaces are allowed to have constructors.
C. A final class cannot be inherited.
D. A subclasss that does not implement the abstract methods of its super
class, should also be declared as an abstract class.

Select the right option based on the above.


a. All statements are true.
b. A, C and D are true.
c. Only C and D are true.
d. A and D are true.

13. What could be the output of the below code?.

a. Father’s method
Father
b. Son’s method
Son
c. Father’s method
Son
d. Son’s method
Father
14. What could be the output of the below code?.

a. Method of Interface I
2
b. Method of Interface I
10
c. Compiler error
d. Method of Interface I
0
15. What could be the output of the below code?.

a. a=0
b=30
b. Compiler error
c. a=0
b=0
d. None

16. Look at the following statements.


A. default access specifier members of a class can be accessed from a
subclass, which is defined in a different package.
B. protected access specifier members of a class can be accessed from a
subclass, which is defined in a different package.
C. protected access specifier members of a class can be accessed from a
non-subclass, which is defined in a different package.
D. public access specifier members of a class can be accessed from any
class irrespective of whether it is a non-subclass or subclass and whether
it is defined in a same package or different package.

Select the right option based on the above.


a. Statement B, C and D are true.
b. Statements A, C and D are true
c. Statements A, B, C and D are true.
d. Statements B and D are true.

17. Look at the following statements:


A. Packages are helpful to prevent name conflcts
B. Packages can be used for controlling access to the members of a class.
C. A Package is simply a directory or folder with java classes.
D. Defining a package inside another package is not permitted.

Select the right option based on the above


a. Statements A and B are true.
b. Statements A, B, and C are true.
c. All statements are true.
d. Statement B, C and D are true.

18. What could be the output of the below program?.

a. Implementation of show function


b. Compiler error
c. Runtime error
d. None
19. What could be the output of the below program?.

a. Constructor of Class A
Constructor of Class B
b. Constructor of Class B
c. Compiler error
d. Runtime error

20. Given the below piece of code

Which of the above lines will give compilation error?


a. line 1
b. line 2
c. line 3
d. Both line 2 and line 4

21. Look at the following statements:


A. StringBuilder and StringBuffer are mutable.
B. String is not mutable.
C. StringBuffer is not a thread safe.
D. StringBuilder is thread safe.

Select the right option based on the above.


a. Statements A, and B are true
b. Statements A, B and C are true
c. Statements A, B and D are true
d. Statement B and C are true.

22. What could be the output of the below code?.

a. Equal
Not Equal
b. Not Equal
Not Equal
c. Compiler error
d. Not Equal
Equal

23. What could be the output of the below code?.

a. false
true
true
false
b. true
false
true
true
c. true
true
false
flase
d. false
false
true
flase
24. Which java regular expression you would choose for the below string S,
whose requirements are provided below?.
S must be of length: 6
First character: 1, 2 or 3
Second character: 1, 2 or 0
Third character: x, s or 0
Fourth character: 3, 0, A or a
Fifth character: x, s or u
Sixth character: a or b
a. ^([1-3][0-2][xs0][30Aa][xsu][ab])$
b. ([1-3][0-2][xs0][30Aa][xsu][ab])
c. ([1-3][0-2][xs0][30Aa][xsu][ab]){6}
d. ^([1-3][0-2][x,s,0][3,0,A,a][x,s,u][ab])$

25. What could be the output of the code shown below.?

a. true
false
true
false
b. true
false
false
true
c. Compiler error
d. true
true
true
true

Section 3: 6 Mark Questions (5*6=30 Marks)


Fill in the blank type questions
1. The objective of the below java program is to check whether the given string is
palindrome or not. Your task is to replace the blanks of the given program such that it
meets the objective.
class S31
{
public static void main(String args[])
{
String str="abcdedcba", rev = "";
int length = str.length();
for ( int i =______; i >= 0; i-- )
rev = ______;
if (______)
System.out.println(str+" is a palindrome");
else
System.out.println(str+" is not a palindrome");
}
}

2. The below program is intended to determine the area of a Rectangle, Square, and
Triangle. The main objective of the below java program is to achive run time
polymorphism through dynamic method dispatch. Your task is to replace the blanks of
the given program such that it meets the objective.
(Anil Kumar Chillara will evaluate for all questions.)

class Rectangle
{
int l=4,b=2;
int area;
public void area()
{
area=l*b;
System.out.println("Area of rectangle: "+area);
}
}
class Square extends Rectangle
{
public void area()
{
area=l*l;
System.out.println("Area of square: "+area);
}
}
class Triangle extends Rectangle
{

public void area()


{
area=_______;//
System.out.println("Area of triangle: "+area);
}
}
public class Calculation
{
public static void main(String args[])
{
Rectangle r=new Rectangle();
r.area();
_____________________;
r.area();
___________________;
r.area();

}
}

3. Java does not support multiple inheritance directly. However, Multiple inheritance can be
achieved using interfaces. The below program is aimed to achieve multiple inheritance.
Your task is to replace the blanks of the given program such that it meets the objective.

(Shravan will evaluate this question for all)

interface I1 {
void eat();
}
interface I2 {
void travel();
}
class Animal implements ______ {
______ void ______ {
System.out.println("Animal is eating");
}
______ void ______ {
System.out.println("Animal is travelling");
}
}
public class S3 {
public static void main(String args[]) {
Animal obj = new Animal();
obj.eat();
obj.travel();
}
}

4. The super keyword in java can be used to refer immediate parent class members. The
objective of the below java program is to use the super keyword in a subclass to call the
constructor of the super class and initialize the members of a superclass as per
requirement. Your task is to replace the blanks of the given program such that it meets
the objective.
(Sahithi will evaluate for all the students)
class Person{
int id;
String name;
Person(int id,String name){
______=id;
______=name;
}
}
class Emp extends Person{
float salary;
Emp(int id,String name,float salary){
______;
this.salary=salary;
}
void display(){
System.out.println(id+" "+name+" "+salary);
}
}
class S3Four{
public static void main(String[] args){
Emp e1=new Emp(5,"arjun",42000.35f);
e1.display();
}
}

5. Regular expressions in java can be used to search for a pattern in an input character
seqeunce. The objective of the below java program is to extract numbers from the input
string. Your task is to replace the blanks of the given program such that it meets the
objective.
(Nida will evaluate this question for all)

import java.util.regex.*;
class S3Five {
public static void main(String args[])
{
Pattern pattern = Pattern.compile(_ _ _ _ _ _ );
Matcher m = pattern.matcher("hello welcome to 2021. Year 2020 is full of
problems");
while (_ _ _ _ _ _)
System.out.println("Extracted pattern "+_ _ _ _ _ _);
}
}

You might also like