Q: 1 ___________ is mechanism by which one class acquires the properties – data fields and methods of another class.
Class
Encapsulation
Inheritance
Polymorphism
[ Option C ]
Inheritance is a fundamental concept in object-oriented programming (OOP) where one class acquires the properties (data fields) and methods of another class. The class inheriting the properties is called the derived class or subclass or child class, while the class from which it inherits is called the base class or superclass or parent class. Inheritance promotes code reusability.
| OOP’S FEATURE | MEANING |
| Encapsulation | Wrapping data and functions into a single unit (class). Protects data from outside interference. It ensures data security and prevents unauthorized access. |
| Abstraction | Hiding unnecessary implementation details and showing only essential features. It provides simplicity by focusing on what an object does, not how it does it. |
| Inheritance | One class acquires the properties and behaviors of another. It promotes code reusability and establishes relationships. |
| Polymorphism | Ability of the same entity (method/operator) to behave differently based on context. It provides flexibility and reduces code complexity. |
Q: 2 _________ is the separation of the logical view of data from its implementation.
Control Structure
Data Abstraction
Testing
Initialization
[ Option B ]
Data Abstraction is the separation of the logical view of data from its implementation details. It allows users to interact with data at a high level without needing to understand the complex underlying details of how data is stored or manipulated. For example, in a database, users can query employee names and salaries without knowing the underlying storage structure or file formats.
Q: 3 The act of combining properties and behaviors related to the same entity is termed as:
Encapsulation
Abstraction
Polymorphism
Delegation
[ Option A ]
In object-oriented programming, an entity is represented using a class, which contains both data (properties) and functions (behaviors).
Encapsulation is the concept of binding or wrapping data members and member functions together into a single unit. This single unit is called a class. It helps in organizing code and protecting data from unauthorized access.
Q: 4
Match the following:
| List – I | List – II |
|---|---|
| (i) A method used to create an instantiation of a class. | (a) Bitmap |
| (ii) A signal that something has happened to stop normal execution of a program. | (b) Type Casting |
| (iii) A graphical image that is usually stored in a file. | (c) Exception |
| (iv) Converting one type of value to another type is called. | (d) Constructor |
(i)-b, (ii)-c, (iii)-d, (iv)-a
(i)-c, (ii)-d, (iii)-b, (iv)-a
(i)-a, (ii)-b, (iii)-c, (iv)-d
(i)-d, (ii)-c, (iii)-a, (iv)-b
[ Option D ]
A constructor is a special member method in a class that automatically called when an object of that class is created. Its main purpose is to initialize the newly created object, such as setting initial values for its attributes. The name of constructor method is same as name the class and no return type (not even void).
public class Bike {
String modelName;
public Bike(String model) {
modelName = model;
}
public void display() {
System.out.println("Bike Model Name : " + modelName);
}
public static void main(String args[]) {
Bike obj = new Bike("Rampayari");
obj.display();
}
}
OUTPUT
Bike Model Name : RampayariAn exception is an unwanted or unexpected event that occurs during the execution of a program and disrupts the normal flow. It indicates that an error or unexpected condition has occurred.
public class ExceptionExample {
public static void main(String args[]) {
try {
int result = 10/0;
} catch (ArithmeticException e) {
System.out.println("Exception Occurred.");
System.out.println("Error: Cannot divide by zero");
}
}
}A bitmap is a type of digital image made of pixels arranged in a grid. Bitmaps are commonly stored in files with extensions like .bmp.
Type casting refers to converting a value from one data type to another. In Java, type casting can be implicit (Widening) or explicit (Narrowing).
Q: 5 Which of the following is NOT an OOP (Object Oriented Programming) principle?
Data Abstraction
Friend Class
Encapsulation
Inheritance
[ Option B ]
Object-Oriented Programming (OOP) is a programming paradigm based on objects, which contain data and methods (code to manipulate that data).
| OOP FEATURE | MEANING |
|---|---|
| Encapsulation | Wrapping data and functions into a single unit (class). Protects data from outside interference. It ensures data security and prevents unauthorized access. |
| Abstraction | Hiding unnecessary implementation details and showing only essential features. It provides simplicity by focusing on what an object does, not how it does it. |
| Inheritance | One class acquires the properties and behaviors of another. It promotes code reusability and establishes relationships. |
| Polymorphism | Ability of the same entity (method/operator) to behave differently based on context. It provides flexibility and reduces code complexity. |
Q: 6 Which of the following is a pillar of OOP?
Inheritance
Encapsulation
Abstraction
More than one of the above
[ Option D ]
Object-Oriented Programming (OOP) is based on several core principles, often called the pillars of OOP.
Encapsulation: Combining data and functions into a single unit (class) and restricting direct access to some of the object’s components.
Inheritance: Creating a new class from an existing class to reuse code and extend functionality.
Abstraction: Hiding the complex implementation details and showing only the essential features to the user.
Polymorphism: Allowing objects to behave differently based on their data type or class.
Q: 7 Which of the following statements is completely true?
I. In an object-oriented programming language, all the function calls are resolved at compile-time.
II. In a procedure programming language, all the function class are resolved at compile-time.
Only II
Only I
Both I and II
More than one of the above
[ Option A ]
In procedural programming languages, all function calls are typically resolved at compile-time, because the functions are fixed and there is no concept of dynamic binding or late binding.
In object-oriented programming languages, not all function calls are resolved at compile-time. Functions that are declared as virtual are resolved at run-time using dynamic binding to support polymorphism. Only non-virtual functions are resolved at compile-time.
Q: 8 How many types of polymorphism are supported by C++?
1
2
3
4
[ Option B ]
Polymorphism in C++ means "one name, many forms", where the same function or operator can behave differently depending on the context (data types or implementations). C++ primarily supports two main types of polymorphism:
Compile-Time Polymorphism: Also called static or early binding, this is resolved during compilation and includes function overloading (same function name with different parameter lists) and operator overloading (redefining operators for user-defined data types).
class Demo
{
public:
void show(int a) { cout <<"Value: " << a; }
void show(double b) { cout <<"Value: " << b; }
};Run-Time Polymorphism: Also called dynamic or late binding, this is resolved during program execution and is achieved through inheritance and the use of virtual functions (function overriding).
class Base
{
public:
virtual void display() { cout <<"Base Class Version."; }
};
class Derived : public Base
{
public:
void display() { cout << "Derived Class Version."; }
};| OOP’S FEATURE | MEANING | REAL-LIFE ANALOGY |
|---|---|---|
| Encapsulation | Wrapping data and functions into a single unit (class). Protects data from outside interference. It ensures data security and prevents unauthorized access. | A capsule that keeps medicine (data) safe inside. |
| Abstraction | Hiding unnecessary implementation details and showing only essential features. It provides simplicity by focusing on what an object does, not how it does it. | Driving a car without knowing the inner mechanics of the engine. |
| Inheritance | One class acquires the properties and behaviors of another. It promotes code reusability and establishes relationships. | A child inheriting traits from parents. |
| Polymorphism | Ability of the same entity (method/operator) to behave differently based on context. It provides flexibility and reduces code complexity. | A person acting as a teacher for student, a husband for wife, a father for children and son for parents. |
Q: 9 If the same entity behave in several forms is known as ___________.
Polymorphism
Redundancy
Publicity
Modularity
[ Option A ]
In object-oriented programming, if an entity behave in more than one form is called polymorphism. The same function, object, or operator can behave differently in different situations.
Q: 10 The act of representing essential information without including background detail is called.
Abstraction
Encapsulation
Inheritance
Polymorphism
[ Option A ]
In object-oriented programming, abstraction means showing only the essential features of an object while hiding unnecessary background details.
Q: 11 Which of the following refers to the wrapping of data and its functionality into a single individual entity?
Modularity
Abstraction
Encapsulation
More than one of the above
[ Option C ]
In object-oriented programming, encapsulation refers to the wrapping of data (variables) and functions (methods) into a single unit, usually a class. This concept ensures that the internal representation of an object is hidden from the outside, and access to the data is only allowed through public methods.
Q: 12 The first object-oriented language was?
Smalltalk
Simula
C++
Pascal
[ Option B ]
The first Object-Oriented Programming (OOP) language was Simula, introducing key concepts like classes, objects, and inheritance. It was developed in the 1960s by Ole-Johan Dahl and Kristen Nygaard.
Q: 13 Which of the following features must be supported by any programming language to become a pure object-oriented programming language?
Encapsulation
Inheritance
Polymorphism
More than one of the above
[ Option D ]
A pure Object-Oriented Programming (OOP) language is one that fully supports the key principles of object-oriented programming called PIE (Polymorphism Inheritance Encapsulation) principle.
Encapsulation: Wrapping data and functions together in a single unit (class) and restricting direct access to some of the components.
Inheritance: Ability of a class to acquire properties and behaviors from another class.
Polymorphism: Ability to take multiple forms, functions or objects to take multiple forms, enabling dynamic behavior.
Q: 14 Which feature of OOP boosts code reusability?
Encapsulation
Polymorphism
Inheritance
Abstraction
[ Option C ]
Object-Oriented Programming (OOP) is built on PIE principles, Polymorphism, Inheritance and Encapsulation. Among these, inheritance is the key feature that significantly boosts code reusability.
Inheritance allows a new class (subclass or derived or child class) to acquire the properties and behavior (data and methods) of an existing class (superclass or base or parent class). This means that the subclass reuses the code already written in the parent class without needing to rewrite it.
Q: 15 The programming language that has the ability to create new data types is called
Overloaded
Encapsulated
Extensible
More than one of the above
[ Option C ]
A programming language is called extensible if it allows the programmer to create new data types in addition to the predefined ones. This feature provides flexibility to model real-world entities and improve code reusability. For example, C++ allows users to define classes, structures, and typedef, which are user-defined types.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.