This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1___________ is mechanism by which one class acquires the properties – data fields and methods of another class.
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.
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: 3The act of combining properties and behaviors related to the same entity is termed as:
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 |
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: 5How the object interacts with each other in object-oriented programming?
Option C
In Object-Oriented Programming (OOP), objects communicate and interact with each other by sending messages. A message usually means calling methods or functions of another object.
#include<iostream>
using namespace std;
class Result
{
public:
void showMarks()
{
cout<<"Marks=77";
}
};
class Student
{
public:
void requestResult(Result r)
{
r.showMarks(); // Message sent to Result object
}
};
int main()
{
Result r1;
Student s1;
s1.requestResult(r1);
return 0;
}
Q: 6Which of the following is NOT an OOP (Object Oriented Programming) principle?
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: 7Which of the following is NOT an object-oriented feature?
Option B
Object-Oriented Programming (OOP) is based on several important features that help in designing reusable, secure, and manageable programs. The major features of OOP are:
| OOP Feature | Purpose |
|---|---|
| Encapsulation | Binds data and its associated functions together in one unit. |
| Inheritance | Acquires properties of another class. |
| Abstraction | Show only essential features and hides unnecessary implementation details. |
| Polymorphism | One entity behaves in multiple (several) forms. |
Q: 8Which of the following is a pillar of OOP?
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: 9Which 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 calls are resolved at compile-time.
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: 10How many types of polymorphism are supported by C++?
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: 11If the same entity behave in several forms is known as ___________.
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: 12The act of representing essential information without including background detail is called.
Option A
In object-oriented programming, abstraction means showing only the essential features of an object while hiding unnecessary background details.
Q: 13Which of the following refers to the wrapping of data and its functionality into a single individual entity?
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: 14Which of the following are object-oriented programming languages?
(I) JAVA
(II) C
(III) C++
(IV) BASIC
Option A
Object-Oriented Programming (OOP) is based on concepts like classes, objects, inheritance, encapsulation, and polymorphism.
Q: 15What is the relation between object and class in an object-oriented programming?
Option C
In Object-Oriented Programming (OOP), a class is a blueprint or template that defines data members and member functions, while an object is a real entity created from that class.
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.