CS2203 - Object Oriented Programming 2 Marks
CS2203 - Object Oriented Programming 2 Marks
2 MARK QUESTIONS
UNIT - I
1. DEFINE ENCAPSULATION
Encapsulation is the process of combining data and functions into a single unit
called class. Using the method of encapsulation, the programmer cannot directly
access the data. Data is only accessible through the functions present inside the
class. Data encapsulation led to the important concept of data hiding.
2. DEFINE DATA-HIDING
Data members (attributes) in a class are declared as private and private members can be
accessed only by functions within the same class. This hides the data from being accessed by
other functions outside the class.
3. DEFINE ABSTRACTION
Abstraction is the process of hiding the inner working details. Classes provide the
abstraction by hiding the complex workings from the user and providing only the essential
details.
4. WHAT IS INHERITANCE
Inheritance is the process by which new classes called derived classes are created from
existing classes called base classes. The derived classes have all the features of the base class
and the programmer can choose to add new features specific to the newly created derived class.
5. WHAT IS POLYMORPHISM
A function with the same name performing different operations is called function
overloading. To achieve function overloading, functions should be declared with the same name
but different number and type of arguments. This comes under compile time polymorphism.
E.g. Two matrices cannot be directly overloaded. But the + operator can be overloaded to
perform addition of two matrices or other user defined data types.
8. DEFINE A CLASS
Classes are data types based on which objects are created. Objects with similar
properties and methods are grouped together to form a Class. Thus a Class represent a set of
individual objects. Characteristics of an object are represented in a class as Properties. The
actions that can be performed by objects becomes functions of the class and is referred to
as Methods.
9. WHAT IS AN OBJECT?
Any real world entity such as pen, book, bird, student etc., can be termed as an object.
In programming, an object is an instance of a class.
10. WHAT ARE THE DIFFERENCES BETWEEN STRUCTURAL AND OBJECT ORIENTED
PROGRAMMING?
The “const” specifier before a variable makes it a constant whose value cannot be
changed during the program. Similarly if it is specified before a pointer, the address contained in
the pointer cannot be modified.
A variable or object declared with the volatile keyword may be modified externally from
the declaring object. Variables declared to be volatile will not be optimized by
the compiler because the compiler must assume that their values can change at any time. Note
that operations on a volatile variable in C and C++ are not guaranteed to be atomic.
13. WHAT ARE STATIC MEMBERS?
Static members are not part of any object and they belong to the entire class. Static
functions cannot be referenced by objects. Static members cannot use the “this” pointer. Static
data members remember their value between function calls.
The various access specifiers available in C++ are private, public and protected.
Methods are functions or procedures that can operate upon the data members of a
class
Default arguments are used when a default value is to be supplied when the user does
not provide any values. The default values can be overridden by the values supplied by the user.