Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

Explain in detail about data encapsulation and inheritance.

Answer»

1. Encapsulation:
It is the method of combining the data and functions within a class. This hides the data from being accessed from outside a class directly and only through the functions inside the class one is able to access the information.

This is also known as “Data Abstraction”, as it gives a clear separation between properties of data type and the associated implementation details. There are two types, known as “function abstraction” and “data abstraction”. A Function when used without knowing how implemented function abstraction. Data abstraction is using data without knowing how the data is stored.

2. Inheritance:
Inheritance is the process of creating a new class, called derived class, from an existing or base classes. The derived class inherits all the capabilities of the base class but in addition, can have its own capability. Inheritance permits code reusability. Once a base class is written and debugged, it need not be touched. Reusing existing code saves time and money and increases a program’s reliability.

Inheritance can also help in the original conceptualization of a programming problem, and in the overall design of the program. A programmer can use a class created by another person or company, and without modifying it, derive at other classes which are suited to particular situations.

2.

Write one advantage of OOP.

Answer»

The object-oriented programming provides improved software development productivity over traditional procedure based programming techniques, because of the factors like modularity, extensibility, and reusability.

3.

What do you mean by inheritance in OOP?

Answer»

Inheritance is the process by which objects can acquire the properties of objects of some other class.

4.

Explain the usage of encapsulation?

Answer»

Encapsulation is the method of combining the data and functions inside a class. This hides the data from being accessed from outside a class directly, and only through the functions inside the class, it is able to access the information. This is also known as “Data Abstraction”, as it gives a clear separation between properties of data type and the associated implementation details.

5.

Briefly explain about dynamic binding.

Answer»

In OOPs dynamic binding refers to linking a procedure call to the code that will be executed only at run time. The code associated with the procedure in not known until the program is executed, which is also known as late binding.

6.

Write a short note on the characteristics of OOP.

Answer»

Basic Characteristics of Object-Oriented Programming:

1. Objects:

An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain/An object may be tangible things like a car, printer, is the sentence incomplete.

In object-oriented programming, a problem is analyzed in terms of objects. Each object contains data and code to manipulate the data. It can be defined as Object = Data + Methods or functions

2. Classes: A class may be defined as a collection of similar objects. In other words, it is a general name for all similar objects. For example, mango, apple, banana all may be described under the common name fruits. A class serves as a blueprint or a plan or a template.

3. Inheritance:

Inheritance is the process by which objects of one class acquire the properties of objects of another class. Inheritance allows to create classes which are derived from other classes so that they automatically include their “parent’s” properties, plus their own. The concept of inheritance provides the idea of reusability, which means additional features can be added to an existing class without modifying it.

4. Reusability:

The reusability implies the reuse of existing code in another program without modification to it. The concept of inheritance provides the basis for reusability in OOP.

5. Creating new data types:

Creating a class in object-oriented programming can be considered as creating new data types.

6. Polymorphism and overloading: 

The property of object-oriented programming polymorphism is the ability to take more than one form in different instances. For example, the same function name can be used for different purposes. Similarly, the same operator can be used for different operations.

7.

Explain the advantages and disadvantages of OOP.

Answer»

The main advantages of OOP are:

  • It is easy to model a real system as real objects are represented by programming objects in OOP.
  • With the help of inheritance, we can reuse the existing class to derive a new class such that the repetition of code is eliminated and the use of the existing class is extended. This saves time and the cost of a program.
  • In OOP, data can be made private to a class such that only member functions of the class can access the data. This principle of data hiding helps the programmer to build a secure program.
  • With the help of polymorphism, the same function or same operator can be used for different purposes. This helps to manage software complexity easily.
  • Large problems can be reduced to smaller and more manageable problems. It is easy to partition the work in a project based on objects.
  • It is possible to have multiple instances of an object to co-exist without any interference i.e. each object has its own separate member data and function.

The few disadvantages of OOP are:
1. Size:

Object-Oriented programs are much larger than other programs. In the early days of computing, space on hard drives, floppy drives and in memory was at a premium. Today we do not have these restrictions.

2. Effort:
Object-Oriented programs require a lot of work to create. Specifically, a great deal of planning goes into an object-oriented program well before a single piece of code is ever written. Initially, this early effort was felt by many to be a waste of time. In addition, because the programs were larger (see above) coders had to spend more time while writing the program.

3. Speed:
Object-Oriented programs are slower than other programs, partially because of their size. Other aspects of Object-Oriented programs also demand more system resources, thus further slowing down the program.

8.

कन्स्ट्रक्टर क्या है? इसे कैसे डिक्लेयर करते हैं? इसकी विशेषताएँ बताइट। 

Answer»

प्रोग्राम में किसी क्लास टाइप का कोई ऑब्जेक्ट बनाने के लिए कम्पाइलर उसके लिए स्थान सुरक्षित करने के लिए एक फंक्शन को कम्पाइल करता है, जिसे कन्स्ट्रक्टर कहा जाता है। कन्स्ट्रक्टर किसी भी प्रकार की कोई वैल्यू रिटर्न नहीं करता। यह स्वतः ही कॉल होता है जब क्लास का ऑब्जेक्ट बनता है। इसका नाम क्लास के नाम के समान ही होता है। कन्स्ट्रक्टर की विशेषताएँ निम्न हैं –

⦁    कन्स्ट्रक्टर्स स्वतः ही कॉल होते हैं, जब ऑब्जेक्ट बनता है।
⦁    कन्स्ट्रक्टर्स स्टैटिक नहीं हो सकते।
⦁    कन्स्ट्रक्टर्स के पास डिफॉल्ट आरग्यूमेण्ट होते हैं।
⦁    कन्स्ट्रक्टर अपनी क्लास के सदस्य फंक्शन को कॉल कर सकता है।

कन्स्ट्रक्टर को घोषित करना

जब कन्स्ट्रक्टर क्रियान्वित होता है तो यह वैल्यू रिटर्न नहीं करता। कन्स्ट्रक्टर को घोषित करने का प्रारूप,
class_name (argument_list);

(i) क्लास के अन्दर कन्स्ट्रक्टर
class Emp
{
public:
int sal;
Emp ()
{
cout<<"Employee Salary"
}
};

(ii) क्लास के बाहर कन्स्ट्रक्टर
class Emp
{
public:
int sal;
Emp ();
};
Emp :: Emp()
cout<<"Employee Salary";
}

9.

कन्स्ट्रक्टर को डिक्लेयर करने के नियम बताइए।

Answer»

कन्स्ट्रक्टर को डिक्लेयर करते समय निम्नलिखित नियमों पर ध्यान देना चाहिए –

⦁    कन्स्ट्रक्टर का नाम वही होना चाहिए जो क्लास का नाम है।
⦁    कन्स्ट्रक्टर्स में पैरामीटर हो सकते हैं।
⦁    कन्स्ट्रक्टर, फंक्शन को ओवरलोड कर सकता है।
⦁    जिस कन्स्ट्रक्टर में कोई आरग्यूमेण्ट नहीं होता, वह डिफॉल्ट कन्स्ट्रक्टर होता हैं।
⦁    कन्स्ट्रक्टर का एक्जीक्यूशन स्वयं होता हैं।
⦁    कन्स्ट्रक्टर को public सेक्शन में डिक्लेयर किया जाता है।
⦁    कन्स्ट्रक्टर का एड्रेस किसी को रेफर नहीं किया जा सकता।
⦁    कन्स्ट्रक्टर स्वतः ही डिफॉल्ट तथा कॉपी कन्स्ट्रक्टर उत्पन्न कर सकता है।

10.

कन्स्ट्रक्टर पर संक्षिप्त टिप्पणी लिखिए। अथवाकन्स्ट्रक्टर शब्द का अर्थ समझाइए। 

Answer»

प्रोग्राम में किसी क्लास टाइप को कोई ऑब्जेक्ट बनाने के लिए कम्पाइलर उसके लिए स्थान सुरक्षित करने के लिए एक फंक्शन को कम्पाइल करता है, जिसे कन्स्ट्रक्टर कहा जाता है। कन्स्ट्रक्टर किसी भी प्रकार की कोई वैल्यू रिटर्न नहीं करता। यह स्वतः ही कॉल होता है जब क्लास का ऑब्जेक्ट बनता है। इसका नाम क्लास के नाम के समान ही होता है।

11.

C++ में, कन्स्ट्रक्टर्स कितने प्रकार के होते हैं?(a) दो(b) तीन(c) चार(d) पाँच

Answer»

(b) C++ में तीन प्रकार के कन्स्ट्रक्टर्स-डिफॉल्ट, पैरामीटराइज्ड तथा कॉपी होते हैं।

12.

कन्स्ट्रक्टर फंक्शन को कैसे इनव्रोक किया जाता है? कन्स्ट्रक्टर | फवशन की चार विशेषताओं को सूचीबद्ध करें। 

Answer»

कन्स्ट्रक्टर फंक्शन को इनवोक करना

#include
class Student
{
public:
Student ()
{
cout<<end1<<"Constructor Function";
}
};
void main ()
{
Student stu;
}

कन्स्ट्रक्टर फंक्शन Student () ऑब्जेक्ट stu के बनते ही स्वत: कॉल हो जाएगा, जो निम्न आउटपुट प्रिण्ट करेगा

Constructor Function

कन्स्ट्रक्टर फंक्शन की विशेषताएँ निम्न हैं –

⦁    कन्स्ट्रक्टर्स स्वतः ही कॉल होते हैं, जब ऑब्जेक्ट बनता है।
⦁    कन्स्ट्रक्टर्स स्टैटिक नहीं हो सकते।
⦁    कन्स्ट्रक्टर्स के पास डिफॉल्ट आरग्यूमेण्ट होते हैं।
⦁    कन्स्ट्रक्टर अपनी क्लास के सदस्य फंक्शन को कॉल कर सकता है।

13.

पैरामीटराइज्ड कन्स्ट्रक्टर को घोषित करने का प्रारूप लिखिए।

Answer»

class_name object_name = constructor, name (arguments);

14.

C++ में प्रोटेक्टेड मेम्बर फंक्शन द्वारा m की घात n के मान ज्ञात कीजिए।

Answer»

#include<iostream.h>
#inclde<conio.h>
class Pow
{
int P, r;
public:
Pow()
{
p=1;
}

protected:

int comp_pow (int a, int b)
{
int i;
for (i=1; i<=b; i++)
p=p*a;
return p;
}
public:
void Result (int m, int n)
{
r=comp_pow (m, n) ;
cout<<"m to the power of n = "<<r;
}
};
void main()
{
clrscr();
Pow obj:
int m, n;
cout<<"Enter the values of m and n:"; cin>>m>>n;
obj. Result (m, n) ;
getch();
}

आउटपुट

Enter the values of m and n: 5
3
m to the power of n = 125

15.

कॉपी कन्स्ट्रक्टर को समझाइए।

Answer»

कॉपी कन्स्ट्रक्टर एक ऐसा कन्स्ट्रक्टर है, जिसके द्वारा किसी ऑब्जेक्ट के प्रारम्भिक मान रखने में उसी क्लास के किसी अन्य ऑब्जेक्ट के मानों का प्रयोग किया जाता है।

16.

निम्नलिखित शब्दों से भाववाचक संज्ञा बनाइए:महान्, सरल, सहज, हरा, समान, शांत।

Answer»

महान् – महानता

सरल – सरलता

सहज – सहजता

हरा – हरियाली

समान – समानता

शांत – शांति।

17.

निम्नलिखित शब्दों का वचन-परिवर्तन कीजिए :(1) नदी (2) किताब(3) दरवाजे (4) कला (5) कौआ (6) धातुएँ (7) सड़कें(8) कुत्ता (9) लड़का(10) कमरा(11) तोता(12) आँख(13) महिला(14) मछली(15) वस्तु(16) वधू 

Answer»

(1) नदी – नदियाँ

(2) किताब-किताबें

(3) दरवाजे – दरवाजा

(4) कला – कलाएँ

(5) कौआ – कौए

(6) धातुएँ – धातु

(7) सड़कें – सड़क

(8) कुत्ता – कुत्ते

(9) लड़का – लड़के

(10) कमरा – कमरे

(11) तोता – तोते

(12) आँख – आँखें

(13) महिला – महिलाएँ

(14) मछली – मछलियाँ

(15) वस्तु – वस्तुएँ

(16) वधू – वधुएँ

18.

वचन बदलकर वाक्य फिर से लिखिए :(1) मैंने कविता लिखी।(2) यह मेरी किताब है।(3) इसे लड्डू दे दो।

Answer»

(1) हमने कविताएँ लिखीं।

(2) ये हमारी किताबें हैं।

(3) इन्हें लड्डू दे दो।

19.

क्लास व ऑब्जेक्ट का प्रयोग करके किसी कर्मचारी (Employee) का ब्योरा (Detail) इनपुट कराके उसे प्रदर्शित कीजिए।

Answer»

#include<iostrean.h>
#include<conio.h>
#include<stdio.h>
class Employee
{
int code;
char name [20], dept [20];
float salary;
public:
void Enter();
void Display();
};
void Employee: : Enter()
{
cout<<"Enter Employee Code:"<<end1; cin>>code;
cout<<"Enter Employee Name:"<<end1;
gets (name);
cout<<"Enter Employee Department:
"<<end1;
gets (dept);
cout<<"Enter Employee Salary:"
<<end1; cin>>salary;
}
void Employee :: Display ( )
{
cout<<"Employee Code:"<<code<<end1;
cout<<"Employee Name:";
puts (name);
cout<<"Employee Department:";
puts (dept);
cout<<"Employee Salary:"<<salary;
}
void main()
{
clrscr();
Employee E;
E.Enter();
E.Display();
getch();
}

आउटपुट

Enter Employee Code:
2550
Enter Employee Name:
Sonam Sharma
Enter Employee Department:
Coordinator
Enter Employee Salary:
35000
Employee Code:2550
Employee Name:Sonam Sharma
Employee Department:Coordinator
Employee Salary:35000

20.

सदस्य या मेम्बर फंक्शन को कितने प्रकार से परिभाषित किया जा सकता है? उदाहरण सहित समझाइए। 

Answer»

सदस्य या मेम्बर फंक्शन को दो प्रकार से परिभाषित किया जा सकता है, जो निम्न प्रकार हैं

(i) क्लास की बॉडी के अन्दर यदि कोई सदस्य फंक्शन बहुत छोटा होता है, तो उसे क्लास की बॉडी में ही परिभाषित कर दिया जाता है ऐसे सदस्यों को इनलाइन माना जाता है।

उदाहरण
class student
{
private:
char name [20];
public:
void enter ()
{
gets (name);
}
void show ()
{
puts (name);
}
};

(ii) क्लास की बॉडी के बाहर यदि फंक्शन बड़े होते हैं, तो क्लास के बाहर ही परिभाषित किए जाने चाहिए, जिसे :: चिह्न का प्रयोग करके परिभाषित किया जाता है। इस चिह्न को स्कोप रिजोल्यूशन ऑपरेटर (Scope resolution operator) कहा जाता हैं।

उदाहरण
class student
{
private:
chiar name [20];
public:
void enter ();
void show ();
};
void Student :: enter ()
{
gets (name);
}
void Student :: show ()
{
puts (name);
}

21.

क्लास का अर्थ समझाइए।

Answer»

क्लास एक ऐसा डाटा तत्त्व है, जिसमें प्रोग्राम के सभी डाटा सदस्यों व फंक्शनों को एक संरचना में व्यवस्थित किया जाता है।

22.

स्कोप रिजोल्यूशन ऑपरेटर की व्याख्या केवल एक वाक्य में कीजिए। 

Answer»

फंक्शन को क्लास के बाहर परिभाषित करने के लिए :: चिह्न का प्रयोग किया जाता है, जिसे स्कोप रिजोल्यूशन ऑपरेटर कहते हैं।

23.

ऑब्जेक्ट क्या होते हैं? 

Answer»

किसी वस्तु, स्थान, व्यक्ति अथवा अन्य इकाई या कार्य को ऑब्जेक्ट कहा जाता है।

24.

किसी ऑब्जेक्ट को कैसे बनाया जाता है? समझाइए।

Answer»

कोई ऑब्जेक्ट किसी क्लास का एक बिन्दु या तत्त्व होता है, जो उस क्लास के नाम से बनाया जा सकता है। ऑब्जेक्ट बनाने का प्रारूप इस प्रकार है –
class_name object_name;
यहाँ, class_name उस क्लासे का नाम है, जिसका ऑब्जेक्ट बनाना है। और object_name उस ऑब्जेक्ट का नाम है, जिसे परिभाषित करना है।

उदाहरण

student S;
यहाँ, क्लास Student का एक ऑब्जेक्ट S है।

25.

पब्लिक सदस्य, प्राइवेट सदस्य व प्रोटेक्टेड सदस्य में भेद कीजिए। अथवाडाटा हाइडिंग क्या है? क्लास के माध्यम से इसे कैसे प्राप्त किया जाता है? उदाहरण सहित समझाइए। 

Answer»

वैरिएबल और फंक्शन की घोषणा private की-वर्ड के द्वारा करने पर इसकी उपलब्धता फंक्शन के बाहर नहीं रहती है अर्थात् इनका प्रयोग उसी फंक्शन में किया जा सकता है, जिस फंक्शन में इन्हें घोषित किया गया है। क्लास की घोषणा का यह गुण डाटा हाइडिंग कहलाता है।
C++ में प्रयुक्त private, public तथा protected सदस्यों को एक्सेस स्पेसीफायर कहा जाता है, जो डाटा हाइडिंग में भी प्रयुक्त होते हैं।
इनका विवरण निम्न है –

⦁    private किसी भी क्लास के private भाग में परिभाषित डाटा आइटम व फंक्शन केवल उसी क्लास के सदस्य फंक्शन द्वारा एक्सेस किए जा सकते हैं।

⦁    protected किसी भी क्लास के protected भाग में परिभाषित डाटा आइटम व फंक्शन उस क्लास के सदस्य फंक्शन तथा डिराइब्ड क्लास के सदस्य फंक्शन द्वारा एक्सेस किए जा सकते हैं।

⦁    public किसी क्लास के public भाग में परिभाषित डाटा आइटम व फंक्शन प्रोग्राम में किसी के भी द्वारा एक्सेस किए जा सकते हैं।

उदाहरण

class Employee
{
private:
char name;
public:
int emp-id;
void input ();
protected:
float salary;
void output ();
};

26.

ऑब्जेक्ट को कैसे पहचाना जाता है?

Answer»

ऑब्जेक्ट को ऑब्जेक्ट के नाम से पहचाना जाता है।

27.

क्लास की परिभाषा का प्रारूप लिखिए और उसके प्रत्येक भाग का अर्थ समझाइए। 

Answer»

क्लास एक ऐसा डाटा तत्त्व है, जिसमें प्रोग्राम के सभी डाटा सदस्यों व फंक्शनों को एक संरचना में व्यवस्थित किया जाता है। C++ भाषा में, क्लास को class कीवर्ड द्वारा परिभाषित किया जाता है।

क्लास को घोषित करने का प्रारूप
class class_name
{
private:
Variable declaration 1;
Function declaration 1;
public:
Variable declaration 2;
Function declaration 2;
};
उपरोक्त प्रारूप में, class एक की-वर्ड है, जो किसी क्लास की शुरुआत करता है। class_name उस क्लास का नाम है, जो यूजर द्वारा रखा जाता है।

⦁    private इसे एक्सेस स्पेसीफायर कहा जाता है, जिसमें परिभाषित डाटा आइटम व फंक्शन केवल उसी क्लास के सदस्य फंक्शन द्वारा एक्सेस किए जा सकते हैं।

⦁    Variable declaration 1 यह क्लास में परिभाषित डाटा आइटम है, जो private भाग में परिभाषित हैं। यह केवल इसी क्लास के अन्दर इसके सदस्य फंक्शन द्वारा एक्सेस किए जा सकते हैं।

⦁    Function declaration 1 यह क्लास में परिभाषित फंक्शन है, जो private भाग के अन्दर परिभाषित है। यह केवल इसी क्लास के अन्दर इसके सदस्य फंक्शन द्वारा एक्सेस किए जा सकते हैं।
public यह एक एक्सेस स्पेसीफायर है, जिसमें परिभाषित डाटा आइटम व फंक्शन किसी के भी द्वारा एक्सेस हो सकते हैं।

⦁    Variable declaration 2 यह क्लास में परिभाषित पब्लिक डाटा आइटम है, जो प्रोग्राम में किसी के भी द्वारा एक्सेस किए जा सकते हैं।

⦁    Function declaration 2 यह क्लास में परिभाषित पब्लिक फक्शन है, जो प्रोग्राम में किसी के भी द्वारा एक्सेस किए जा सकते हैं।
}; यह क्लास के अन्त को प्रदर्शित करता है।

उदाहरण
class Teacher
{
public:
int Id;
void Subject ();

private:

int no_of_lecture;
void Department ();
};

28.

फ्रेण्ड फंक्शन की व्याख्या केवल एक वाक्य में कीजिए। 

Answer»

फ्रेण्ड फंक्शन का प्रयोग friend की-वर्ड के साथ किया जाता है। ये क्लास के मेम्बर फंक्शन नहीं होते, परन्तु उस क्लास के private और protected मेम्बर को एक्सेस कर सकता है।

29.

क्लासेज तथा ऑब्जेक्ट के सिद्धान्त की व्याख्या कीजिए। अथवाक्लासेज तथा ऑब्जेक्ट का वर्णन कीजिए। 

Answer»

क्लास क्लास एक ऐसा तत्त्व है, जिसमें प्रोग्राम के सभी डाटा सदस्यों व फंक्शनों को एक संरचना में व्यवस्थित किया जाता है। वस्तुओं को उनके समान व्यवहार और सम्भव स्थितियों के अनुसार समूहों में बाँटा जाता है, ऐसे प्रत्येक समूह को क्लास कहा जाता है।

ऑब्जेक्ट किसी वस्तु, स्थान, व्यक्ति अथवा अन्य इकाई या कार्य को ऑब्जेक्ट कहा जाता है। कोई ऑब्जेक्ट किसी क्लास का एक बिन्दु या तत्त्व होता है, जो उस क्लास के नाम से बनाया जा सकता है।

30.

निम्न में से ऑब्जेक्ट को परिभाषित करने का प्रारूप कौन-सा है?(a) class_name object_name(b) class_name object_name;(c) object_name class_name;(d) object_name;

Answer»

(b) class_name object_name;

31.

सदस्य फंक्शन को कितने प्रकार से परिभाषित किया जा सकता है?a) तीन(b) चार(c) दो(d) एक

Answer»

(c) सदस्य फंक्शन को दो प्रकार से परिभाषित किया जा सकता हैक्लास बॉडी के अन्दर तथा क्लास बॉडी के बाहर।

32.

डिफॉल्ट कन्स्ट्रक्टर किसे कहते हैं?

Answer»

जिस कन्स्ट्रक्टर फंक्शन में कोई आरग्यूमेण्ट नहीं होता, उसे डिफॉल्ट कन्स्ट्रक्टर कहा जाता है।

33.

कॉपी कन्स्ट्रक्टर का प्रारूप क्या है?(a) class_name object 2 = object 1;(b) class_name object 1 = object 2;(c) class_name object 2:(d) class_name object 2();

Answer»

(a) class_name object 2 = object 1;

34.

आरग्यूमेण्ट वाले कन्स्ट्रक्टर को क्या कहा जाता है?(a) कॉपी कन्स्ट्रक्टर(b) डिफॉल्ट कन्स्ट्रक्टर(c) फंक्शन कन्स्ट्रक्टर(d) पैरामीटराइज्ड कन्स्ट्रक्टर

Answer»

(d) पैरामीटराइज्ड कन्स्ट्रक्टर

35.

क्लास में प्रयुक्त protected वई क्या है?

Answer»

protected एक एक्सेस स्पेसीफायर है, जो प्रोग्राम में किसी क्लास के अन्दर प्रयोग किया जाता है।

36.

क्लास के सदस्य कौन होते हैं?

Answer»

क्लास में प्रयुक्त डाटा आइटम तथा फंक्शन क्लास के सदस्य होते हैं।

37.

क्लास से क्या तात्पर्य है? किसी क्लास को किस प्रकार से डिक्लेयर किया जा सकता है? समझाइए। 

Answer»

क्लास एक ऐसा डाटा तत्त्व है, जिसमें प्रोग्राम के सभी डाटा सदस्यों व फंक्शनों को एक संरचना में व्यवस्थित किया जाता है। C++ भाषा में, क्लास को class की-वर्ड द्वारा परिभाषित किया जाता है।
क्लास को डिक्लेयर करना क्लास को डिक्लेयर करते समय, क्लास के सभी डाटा सदस्य व फंक्शन को क्लास के अन्दर ही व्यवस्थित किया जाता है।

प्रारूप

class class_name

{

private:
Variable declarations;
Function declarations;
public:
Variable declarations;
Function declarations;

};

38.

निम्न में से कौन-सा कथन असत्य है?(a) C++ क्लास में डाटा आइटम तथा फंक्शन होते हैं।(b) C++ क्लास में मात्र फंक्शन होते हैं।(c) एक क्लास में अनेक ऑब्जेक्ट डिक्लेयर किए जाते हैं।(d) ऑब्जेक्ट का प्रारूप क्लास की भाँति होता है।

Answer»

(b) दिए गए विकल्पों में (b) असत्य है, क्योंकि C++ क्लास फंक्शन के साथ-साथ डाटा आइटम भी रखता है।

39.

किस क्लास के डाटा आइटम व फंक्शन को अन्य क्लास द्वारा एक्सेस किया जा सकता है?(a) public(b) private(c) protected(d) इनमें से कोई नहीं

Answer»

(a) public क्लास में परिभाषित डाटा आइटम व फंक्शन को किसी भी अन्य क्लास द्वारा एक्सेस किया जा सकता है।

40.

फंक्शन को क्लास के बाहर परिभाषित करने के लिए किस चिह्न का प्रयोग किया जाता है?(a) :(b) :(c) : ?(d) ::

Answer»

सही विकल्प है (d) ::

41.

डिस्ट्रक्टर को कैसे घोषित किया जाता है? समझाइए।

Answer»

डिस्ट्रक्टर को दो प्रकार से घोषित किया जा सकता है, जो निम्न प्रकार हैं।

(i) क्लास के अन्दर डिस्ट्रक्टर

class Teacher
{
public:
Teacher ()
{
cout<<"Teacher is Present";
}
~Teacher ()
{
cout<<"Teacher is Absent";
}
};

(ii) क्लास के बाहर डिस्ट्रक्टर

class Teacher
{
public:
Teacher ()
{
cout<<"Teacher is Present";
}
~Teacher ();
};
Teacher :: ~ Teacher ()
{
cout<<"Teacher is Absent";
}

 

42.

प्रोग्राम में क्या, ऑब्जेक्ट के निर्माण के समय स्वतः ही क्रियान्वित हो जाता है?(a) कन्स्ट्रक्टर(b) डिस्ट्रक्टर(c) क्लास(d) फंक्शन

Answer»

सही विकल्प है (a) कन्स्ट्रक्टर

43.

डिस्ट्रक्टर की विशेषताएँ बताइए।

Answer»

डिस्ट्रक्टर की विशेषताएँ निम्न हैं –

⦁    एक डिस्ट्रक्टर के पास डिफॉल्ट आरग्यूमेण्ट हो सकते हैं।
⦁    डिस्ट्रक्टर अपनी क्लास के सदस्य फंक्शन को कॉल कर सकता है।
⦁    ये स्टैटिक नहीं हो सकते।
⦁    ये स्वतः कॉल होते हैं, जब ऑब्जेक्ट्स सीमा (Scope) से बाहर जाते हैं।

44.

कन्स्ट्रक्टर तथा डिस्ट्रक्टर में अन्तर बताइए। 

Answer»

कन्स्ट्रक्टर तथा डिस्ट्रक्टर में निम्न अन्तर है

कन्स्ट्र क्टरडिस्ट्रक्टर
ये स्वतः ही कॉल होते हैं, जब ऑब्जेक्ट बनता है।ये स्वतः ही कॉल होते हैं, जब ऑब्जेक्ट सीमा (Scope) से बाहर जाता है।
कन्स्ट्रक्टर का नाम क्लास के नाम के समान होता हैं।हिस्ट्रक्टर का नाम क्लास के नाम के समान होता है, परन्तु उसमें पहले टाइल्या (~) प्रीफिक्स का प्रयोग किया जाता है।

45.

कन्स्ट्रक्टर के प्रकार पर संक्षिप्त टिप्पणी लिखिए। 

Answer»

कन्स्ट्रक्टर के विभिन्न प्रकार
· Default Constructor – कन्स्ट्रक्टर फंक्शन जिसमें कोई parameter pass नहीं किया जाता है उसे Default Constructor कहते हैं ।
· Parameter Constructor – ऐसे कन्स्ट्रक्टर फंक्शन जिसमें argument pass किया जाता है उसे Parameter Constructor कहते हैं ।
· Copy Constructor – ऐसे कन्स्ट्रक्टर फंक्शन जो कि अपने ही वर्ग का एक reference parameter की तरह स्वीकार करते हैं ।

46.

Write a short note on the techniques of programming

Answer»

1. Procedural programming technique:

It is a list of instructions telling a computer, step-by-step, what to do, usually having a linear order of execution from the first statement to the second and so forth with occasional loops and branches. Procedural programming languages include c, C++, etc.

Some of the benefits of the procedural programming methodology are:

  • Easy to read program code.
  • Easily maintainable program code, as various procedures can be debugged in isolation.
  • The code is more flexible as one can change a specific procedure that gets implemented across the program.

2. Structured programming technique: Structured programming deals only with logic and code, and suggests making use of programming structures such as sequence, selection, iteration and modularity in programs

Features:

  • It focuses on techniques for developing good computer programs and problem solution.
  • It is most important to consider single-entry and single-exit control in a program and structures.
  • Structured code is like a page, which can be read from the top to bottom without any backward references.
  • Read from top to bottom makes the code easy to read, test, debug, and maintain.

3. Object-oriented technique:

Object-oriented programming is a method of programming where a system is considered as a collection of objects that interact together to accomplish certain tasks. Objects are entities that encapsulate data and procedures that operate on the data. The main purpose of objectoriented programming is to simplify the design, programming and most importantly debugging a program.

So to modify a particular data, it is easy to identify which function to use. The important elements of OOP are objects, classes, abstraction, encapsulation, polymorphism, and inheritance.

47.

Compare objects and classes.

Answer»

A class is a definition of an object. It is a data type like int. A class is a type, and an object of this class is just like a variable. In other words, the class is a blueprint and an object can be considered as any real-time entity (existing thing) that can perform a set of related activities.

48.

क्लास में प्रयुक्त एक्सेस स्पेसीफायर कितने प्रकार के होते हैं?(a) तीन(b) दो(c) चार(d) पाँच

Answer»

(a) एक्सेस स्पेसीफायर तीन प्रकार के होते हैं –
private, protected 24 public

49.

डिस्ट्रक्टर का अर्थ समझाइए। अथवाडिस्ट्रक्टर को उदाहरण सहित समझाइए। 

Answer»

यह किसी क्लास का एक विशेष सदस्य फंक्शन होता है, जो तब क्रियान्वित होता है जब उस क्लास का ऑब्जेक्ट सीमा (Scope) से बाहर जाता है।
इसका नाम भी वही होता है, जो क्लास का नाम होता है, परन्तु उसमें पहले टाइल्ड (~) प्रीफिक्स का उपयोग किया जाता है।

उदाह्रण डिस्ट्रक्टर की क्रियाविधि

#include<iostream.h>
#include<conio.h>
class Line
{
private:
double length;
public:
void set Length (double len);
double getLength ();
Line (); //This is the constructor
//declaration
~Line(); //This is the destructor
//declaration
};
Line :: Line () //Constructor definition
{
cout<<"Object is being created"<<end1;
}
Line : : ~Line() //Destructor definition
{
cout<<"Object is being deleted"<<end1;
}
void Line :: set Length (double len)
{
length = len;
}
double Line :: getLength()
{
return length;
}
void main()
{
Line line; line.setLength(6.0); //set line length
cout<<"Length of line";
cout<<line.getLength() <<end1;
getch();
}

आउटपुट

0bject is being created
Length of line 6
Object is being deleted

50.

Mention one application of OOP.

Answer»

Main application areas of OOP are

  • User interface design such as windows, menu
  • Object-oriented databases