OOP - Object Oriented Programming, Past Papers, UOS Main Campus

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

LineErrorCorrection
6public 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() { }
12extend is not a keywordclass YourClass extends MyClass
17display_dat() — method not founddisplay_data();
19Variable e is not declaredPrint an existing field, e.g. d
24main is not static, so the program cannot be launched (not a compile error, but wrong entry point)public static void main(String[] arg)
27No constructor YourClass(int,int) existsAdd a constructor YourClass(float c, int d) or call new YourClass()
28ob3 is not declared, and the + operator cannot be applied to objectsRemove the line (Java has no operator overloading)
30ob1.c; is not a statement, and c is not a member of MyClassRemove it, or e.g. System.out.println(ob2.c) inside YourClass
31ob2.display_data; — missing parentheses, not a statementob2.display_data();
32Closing brace of class TestAbc is missingAdd }
4 / 8a is private: it is fine inside MyClass but not accessible from YourClassUse 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.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.