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: 9In C++, trying to access private data from outside of a class throws error. This feature is known as:
Option C
Data Hiding is one of the fundamental features of Object-Oriented Programming (OOP). It means restricting direct access to the internal data of a class to protect it from unauthorized modification.
Q: 10Which 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.
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.