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: 2What is Encapsulation in Java?
Option C
Encapsulation in Java is one of the fundamental principles of Object-Oriented Programming (OOP). An act of combining data (variables) and the methods that operate on that data into a single unit called a class.
Through encapsulation, the internal details of an object are hidden from the outside world, allowing controlled access via getter and setter methods. This helps maintain data security, ensures better control over the data, and prevents unintended modification.
| CONCEPT | DESCRIPTION | KEY FEATURES |
|---|---|---|
| Encapsulation | The OOP principle of combining data (variables) and methods (functions) into a single unit and restricting direct access to it. |
|
| Class | A blueprint or template from which objects are created. It defines properties (variables) and behaviors (methods). |
|
| Object | An instance of a class that has its own identity, state, and behavior. It occupies memory. |
|
Q: 3A class that exhibits a high degree of primitiveness encapsulates only ______________ operations.
Option B
In object-oriented programming, a class is a blueprint for creating objects and can encapsulate (combine) data (variable) and operations (methods). The degree of primitiveness of a class refers to how basic or elementary its responsibilities are.
Q: 4Which 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: 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;
}
You have reached the end of this topic. Continue learning with the next topic below.
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.