Midsem 2021 (Solved)
Midsem 2021 (Solved)
Midsem 2021 (Solved)
Q1 Q2 Q3
a) Compilation fails
b) 21
c) Stack Overflow Error
d) 28
e) 29
1
1. public class Abc {
2. public static String s = "";
3. public static void compute() {
4. s +="Computing ";
5. }
6. }
7. public class Xyz extends Abc {
8. public static void compute() {
9. s += "Suspension";
10. }
11. public static void main(String args[]) {
12. Abc b1 = new Abc ();
13. Abc b2 = new Xyz();
14. Abc b3 = (Xyz)b2;
15. Xyz b4 = (Xyz)b2;
16. b1.compute();
17. b1.compute();
18. b3.compute();
19. b4.compute();
20. System.out.println(s);
21. }
22. }
2
16. Mno(String str1){
17. str += str1;
18. new Xyz(str);
19. }
20. public static void main(String args[]) {
21. new Mno("tu ");
22. System.out.println(str);
23. }
24. }
a) s tu s tu s
b) t tu t s tu t t tu t s tu t s
c) t s tu t t s tu
d) t st tu tu tu s tu t s
e) Compilation fails.
f) Runtime exception
ANS: ___________________________________________________
3
6. /* MISSING CODE */
7. System.out.println("Programming");
8. }
9. }
10. public class Xyz extends Abc{
11. Xyz(int a){
12. super(a);
13. }
14. public static void main(String args[]) {
15. new Xyz(10);
16. }
17.
18. }
ANS: _________________________________________________________
___________________________________________________________________
Scenario-based question:
1. Refer to the below illustration of various entities in IPL. You are required to clearly
write classes and their association with each other. Also, figure out the methods
of each entity and their polymorphism (if exist). [11]
4
Blank page for the answer.
5
BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, PILANI
DEPARTMENT OF COMPUTER SCIENCE AND INFORMATION SYSTEMS
OBJECT-ORIENTED PROGRAMMING (CSF212)
1ST SEMESTER 2021-22 MID-SEMESTER EXAMINATION
COMPLETELY CLOSED BOOK
PART-B
MAX TIME: 90 Minutes MAX MARKS 60
------
Instructions:
1. Answer all the parts of a question together in the answer sheet. Answers at separate
places will not be accepted.
2. Please don’t write any information not relevant to the question.
3. Use your time judiciously.
1. One of your friends ask you about the checked and unchecked exceptions. If it's a type
of exception, how do we check it at the compile time? Why would you call them
exceptions, when they are checked at compile-time? Explain the concept of exceptions
to very beginner moving towards the deep technical details of the types and broad
categories. Illustrate the classification of exceptions with diagram(s) of checked and
unchecked exceptions and their sub-classes.
[11 Marks]
(~ 6 to 9 Minutes)
3. I have used a very dynamic list of over a hundred million elements with lots of additions
and deletions over the course of my application. I need to access the elements in a quick
time. I need to access them with the index number. I do a lot of searching in the array. In
fact, over 99% of my operations are that of searching the element to check if the element
is present or not in the array. Analyse the following collections on the basis of the above
requirements.
a. ArrayList
b. LinkedList
c. HashSet
d. Stack [15 Marks]
(~ 7 to 10 Minutes)
1
4. Multitasking has been a dream of every person and is present in every resume for the
last 20 years. We know of multithreading in Java. What's the difference between
multitasking and multithreading? In Java multithreading gives non-deterministic results.
Why? What are two ways/concepts/techniques using which I can move towards
determinism in Java using multithreading? Discuss them in brief.
[5+5+5 = 15 Marks]
(~7 to 10 Minutes)
5. You have done a lot with streams in your career as a programmer. A junior asks you,
why would anyone use PrintWriter class to print on screen when he/she can do the
same with FileOutputStream class? Why should I use any of the above if you can use
classes like Scanner and System.out? Explain to your junior the technical details of all
four with the differences and utilities while explaining the purpose of each one of them.
[5+5+5 = 15 Marks]
(~10 to 12 Minutes)
-------------------------END------------------------------
2
Part A Solutions
Answer:
Bidding is a class with Bidding date and Bidding venue as its data members. Methods
include Announcement of tender, Bid submission, Bid for more than one city, and
Governing council approval. [1 mark]
Auction is a class with Player 1 andTeam 1 as objects of Player and Team classes
respectively as its data members. Methods include Confirm player, Decline player, and
Notify player. [1 mark]
Player is a class with Player name, Base price, and Nationality as its data members.
Methods include Batting performance, Bowling performance, Fielding performance,
Leadership qualities, and Overall score. [1 mark]
Team is a class with Team name, Coach name, and Team owner as its data members.
Methods include Playing eleven structure, Bid submission, Confirm player, and
Governing council approval. [1 mark]
Match is a class with Team 1 and 2 as objects of Team class as its data members.
Methods include Date of match, venue of match, and Governing council approval.
[1 mark]
Tournament is a class with Player all, Team all, and Match all as objects of Player,
Team, and Match classes respectively as its data members. Methods include IPL
schedule, Playing eleven structure, and Overall score. [1 mark]
Polymorphism: [1 * 5 = 5 marks]
a) Compilation fails
b) 21
c) Stack Overflow Error
d) 28
e) 29
a) s tu s tu s
b) t tu t s tu t ttu t s tu t s
c) t s tu t t s tu
d) t sttututu s tu t s
e) Compilation fails.
f) Runtime exception
Writing correct code:
4. Write the signature for the generic child class Xyz whose parent is a generic
class Abc<T>. Write Exact Java Syntax. [4]
1. public class Abc<T> {
2. T obj1;
3. }
4. // WRITE SIGNATURE OF THE SUBCLASS Xyz
5. U obj2;
6. Xyz(T obj1, U obj2){
7. this.obj1 = obj1;
8. this.obj2 = obj2;
9. }
10. void show(){
11. System.out.println("T = "+obj1+ "U = "+obj2);
12. }
13. public static void main(String args[]) {
14. Xyz s = new Xyz(1.0, 2);
15. s.show();
16. }
17. }
Answer: public class Xyz <T, U> extends Abc <T>