You are on page 1of 2

Sindh Madressatul Islam University

Department of Computer Science


BS (CS) 2nd Semester
Object-Oriented Programming CSC104
Quiz # 1 Solution

Date: 26-09-16
Duration: 30 minutes
Marks: 20

Note: Attempt all questions.

Q1. We have a class named Sales with a method name CalculateSales(). We need to use it in the
class WinterSales, class SummerSales. So for every class we use the CalculateSales() method but
with different attributes. Mention which key concept of object-oriented does this scenario refer to
and define that concept. (05)
Ans. This concept refers to Polymorphism.
Polymorphism is defined as the implementation of the same method with different
attributes in a different context.
Q2. (a) Write any four differences between Abstraction and Encapsulation. (04)

Ans.

Abstraction Encapsulation
1. Abstraction solves the problem at the 1. Encapsulation solves the problem in the
design level. implementation level.

2. Abstraction hides unwanted data 2. Encapsulation means hiding the code and
and provides relevant data. data into a single unit to protect the data
from the outside world.
3. Abstraction lets you focus on what the 3. Encapsulation means hiding the internal
object does instead of how it does it details or mechanics of how an object does
something.
4. Abstraction: Outer layout, used in terms 4. Encapsulation: Inner layout, used in
of design. terms of implementation.
(b) Write any three differences between Structured Programming and Object-oriented
Programming. (03)

Ans.

Structured Programming Object Oriented Programming


1. Structured Programming is designed 1. Object Oriented Programming is designed
which focuses on process/ logical structure which focuses on data.
and then data required for that process.

2. Structured programming follows top- 2. Object oriented programming


down approach. follows bottom-up approach.
3. In Structured Programming, Programs 3. In Object Oriented Programming,
are divided into small self- Programs are divided into small entities
contained functions. called objects.

Q3. Define following: (08)

OO Process Model
Ans. Object-oriented model is a representation of a piece of software as a set of
objects interacting between each other, with a goal to reduce the complexity of the
system and enable developers to work on a specific object, while treating other
objects as black boxes, with the requirement to know only their interfaces, and not
their actual implementation.

Class
Ans. A class is grouping of objects with similar properties. A class is a blueprint of
an object that contains variables for storing data and functions to perform
operations on the data.

Objects
Ans. Objects are instances of any class and primary run-time entities that make
sense in a specific application. They may represent a person, a place or any item that
the program must handle. To work with the data represented by the class a variable
for the class must be created, that is called an object.

Inheritance
Ans. When a class includes a property of another class it is known as inheritance.
Inheritance is a process of object reusability. Inheritance is a feature by which a
class acquires attributes of another class.

You might also like