Blog
OOP CMP-2123 BSIT BSSE 2nd Final Past Paper 2015 – UOS Main Campus
ProgramBSIT
Semester2nd
ExamFinal Term
Year2015
AnswersSolved ✓
University of Sargodha main campus (Department of Computer Science & IT) Object Oriented Programming (CMP-2123) final exam for BSIT and BSSE 2nd semester, 15 June 2015. Retyped from the original paper, with solved answers below.
Paper set byMr. Muhammad IqbalView official UOS faculty profile →
The available copy of this paper starts from Question 2.
Solved answers
Q2 – Compile-time errors
| Line | Error | Correction |
|---|---|---|
| 6 | public void MyClass() is a method, not a constructor (constructors have no return type). It compiles, but there is no real constructor. | Remove void: public MyClass() { } |
| 12 | extend is not a keyword | class YourClass extends MyClass |
| 17 | display_dat() — method not found | display_data(); |
| 19 | Variable e is not declared | Print an existing field, e.g. d |
| 24 | main is not static, so the program cannot be launched (not a compile error, but wrong entry point) | public static void main(String[] arg) |
| 27 | No constructor YourClass(int,int) exists | Add a constructor YourClass(float c, int d) or call new YourClass() |
| 28 | ob3 is not declared, and the + operator cannot be applied to objects | Remove the line (Java has no operator overloading) |
| 30 | ob1.c; is not a statement, and c is not a member of MyClass | Remove it, or e.g. System.out.println(ob2.c) inside YourClass |
| 31 | ob2.display_data; — missing parentheses, not a statement | ob2.display_data(); |
| 32 | Closing brace of class TestAbc is missing | Add } |
| 4 / 8 | a is private: it is fine inside MyClass but not accessible from YourClass | Use protected or a getter if needed |
Q3 – Student, Employee and Scientist classes
import java.util.Scanner;
class Student {
String degree;
void input(Scanner sc) { System.out.print("Degree: "); degree = sc.nextLine(); }
void display() { System.out.println("Degree: " + degree); }
}
class Employee {
String name;
void input(Scanner sc) { System.out.print("Name: "); name = sc.nextLine(); }
void display() { System.out.println("Name: " + name); }
}
class Scientist {
int publications;
Employee emp = new Employee();
Student stu = new Student();
void input(Scanner sc) {
emp.input(sc);
stu.input(sc);
System.out.print("Publications: ");
publications = sc.nextInt();
}
void display() {
emp.display();
stu.display();
System.out.println("Publications: " + publications);
}
}
public class TestScientist {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scientist s = new Scientist();
s.input(sc);
s.display();
}
}Scientist uses composition: it has an Employee object (for name) and a Student object (for degree) plus its own publications field; only input and display methods are used, as required.
Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
