Object Oriented Programming
SWE · Midterm · Fall 26
Batch 45
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Daffodil International University
Faculty of Science & Information Technology
Department of Software Engineering
Midterm Examination, Fall 2026
Course Code: SE216; Course Title: Object Oriented Programming
Sections & Teachers: RJM(A,B,C), KUS(D,E,H), MRS(F,G), TM(I,J), MHM(K)
Time: 1 Hour 30 Mins
Marks: 25
Answer ALL Questions
[The figures in the right margin indicate the full marks and corresponding course outcomes. All portions of each question must be answered sequentially.]
1. a) Convert the below class diagram to the appropriate Java code by using the concept of Encapsulation. [6]
[Figure: Class diagram showing Laptop class with attributes - brand: String, - price: double, and methods + Laptop(String, double), + updateVersion(String, double): void, + getBrand(): String, + getPrice(): double, and LaptopTest class with + main(String[] args): void]
Expected Output:
Brand: HP
Price: 75000.0
Brand: Lenovo
Price: 85000.0
b) Compute the output of the following code: [4]
public class Robot {
String name;
int energy;
static int count = -1;
Robot(String n, int e) {
name = n;
energy = e;
count += 2;
System.out.println(name + " " + count);
}
void charge(int energy) {
int bonus = 5;
this.energy += energy + bonus;
System.out.println(bonus);
System.out.println(this.energy);
}
void show() {
System.out.println(name + " " + count);
}
static void display() {
System.out.println(count);
}
public static void main(String[] args) {
Robot r1 = new Robot("Rex", 10);
Robot r2 = new Robot("Zed", 20);
r1.charge(5);
r2.show();
r1.name = "Max";
Robot.display();
r1.show();
System.out.println(r2.energy);
}
}
2. a) Review the given code below and write the Gamer, ProGamer, and GameLegend classes (Design Classes) to produce the expected output. Here, you have to deal with Inheritance, Upcasting, Downcasting, Dynamic Method Dispatch, Constructor Overloading, Method Overloading, and Method Overriding. [12]
// Rewrite your design classes here:
Driver Code:
public class GameArena {
public static void main(String[] args) {
Gamer gamer = new GameLegend("Nova");
ProGamer pro = new GameLegend();
GameLegend legend = new GameLegend("Shadow", 90);
gamer.play();
pro.play();
legend.play();
legend.play("Minecraft");
((Gamer) legend).chill();
pro.train();
System.out.println("Level: " + ((GameLegend) gamer).level);
}
}
Expected Output:
Nova: Unstoppable!
Noob: Unstoppable!
Shadow: Unstoppable!
Shadow: Minecraft time!
Shadow: AFK
Noob: Grinding XP
Level: 50
b) [2+1]
package family;
public class Guardian {
int age = 50;
}
package adventure;
import family.Guardian;
public class Hero extends Guardian {
public static void main(String[] args) {
Hero h = new Hero();
System.out.println(h.age);
}
}
Observe the above code and answer the following questions.
i) Will the code compile successfully? Justify your answer.
ii) Write the minimum change required to fix the compilation error, if any.