FliQi Education App Download
प्रश्न-बैंक · C++ Language

Inheritance — प्रश्न और उत्तर

C++ Language · 20 जाँचे हुए (verified) प्रश्न

  • 20 जाँचे हुए प्रश्न
  • हिंदी + English

पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 10 के उत्तर और हल FliQi Question Bank app में।

भाषा
प्रश्न 1उत्तर + हल
यदि multilevel इनहेरिटेंस में class C, class B से इनहेरिट करती है और class B, class A से इनहेरिट करती है, तो class C का object बनाने पर उनके destructors किस क्रम में चलेंगे?
In multilevel inheritance, class C inherits class B, and class B inherits class A. In which sequence are their destructors called if an object of class C was declared?
  1. A~A() फिर ~B() फिर ~C()~A() then ~B() then ~C()
  2. B~C() फिर ~A() फिर ~B()~C() then ~A() then ~B()
  3. C~C() फिर ~B() फिर ~A()~C() then ~B() then ~A()
  4. D~B() फिर ~C() फिर ~A()~B() then ~C() then ~A()

सही उत्तर / Answer: (C)

हल / Solution
Object बनते समय constructors ऊपर से नीचे चलते हैं, यानी पहले A(), फिर B(), फिर C()। Object मिटते समय destructors ठीक उलटे क्रम में चलते हैं। पहले सबसे नीचे की class का ~C() चलता है, फिर ~B() और आख़िर में ~A()। कारण यह है कि derived class का हिस्सा base पर टिका होता है, इसलिए पहले उसे साफ़ किया जाता है। इसलिए सही क्रम ~C(), ~B(), ~A() है। बाक़ी विकल्पों का क्रम इस नियम से मेल नहीं खाता।
When an object is created, constructors run from top to bottom, first A(), then B(), then C(). When the object is destroyed, destructors run in exactly the reverse order. First the lowest class destructor ~C() runs, then ~B(), and last ~A(). This is because the derived part depends on the base part, so it is cleaned up first. So the correct order is ~C(), ~B(), ~A(). The other options break this rule.
प्रश्न 2उत्तर + हल
डायमंड समस्या (diamond problem) क्या है?
What is the diamond problem?
  1. Aडायमंड समस्या multilevel इनहेरिटेंस के कारण होती हैDiamond problem occurs due to multilevel inheritance
  2. Bडायमंड समस्या multiple इनहेरिटेंस के कारण होती हैDiamond problem occurs due to multiple inheritance
  3. Cडायमंड समस्या hybrid इनहेरिटेंस के कारण होती हैDiamond problem occurs due to hybrid inheritance
  4. Dडायमंड समस्या single इनहेरिटेंस के कारण होती हैDiamond problem occurs due to single inheritance

सही उत्तर / Answer: (B)

हल / Solution
डायमंड समस्या तब बनती है जब class B और C दोनों class A से बनी हों और class D एक साथ B और C से इनहेरिट करे। तब D में A की दो प्रतियाँ आ जाती हैं और A का सदस्य बुलाना अस्पष्ट हो जाता है। इसकी जड़ एक class के दो parent होना है, यानी multiple इनहेरिटेंस। Hybrid में यह तभी आती है जब उसमें multiple शामिल हो। Single और multilevel में यह नहीं होती।
The diamond problem arises when classes B and C both derive from class A, and class D inherits from both B and C. Then D gets two copies of A, and the compiler cannot decide which copy to use when a member of A is called. The root cause is one class having two parents, which is multiple inheritance. Hybrid shows it only when it includes multiple. Single and multilevel give each class only one parent.
प्रश्न 3उत्तर + हल
किस प्रकार के इनहेरिटेंस में private इनहेरिटेंस शामिल नहीं हो सकता?
Which type of inheritance cannot involve private inheritance?
  1. Aएकल स्तर (Single level)Single level
  2. Bमल्टीपल (Multiple)Multiple
  3. Cहाइब्रिड इनहेरिटेंस (Hybrid)Hybrid inheritance
  4. Dसभी प्रकारों में private इनहेरिटेंस हो सकता हैAll types have private inheritance

सही उत्तर / Answer: (D)

हल / Solution
Private इनहेरिटेंस का मतलब है class D : private B लिखना। तब base के public और protected सदस्य derived class में private बन जाते हैं। यह access specifier हर तरह के इनहेरिटेंस में लगाया जा सकता है। Single में एक base के साथ, multiple में हर base के साथ अलग-अलग, और hybrid में भी। कोई प्रकार इसे रोकता नहीं है। इसलिए पहले तीन विकल्प ग़लत हैं और सही उत्तर है कि सभी प्रकारों में private इनहेरिटेंस हो सकता है।
Private inheritance means writing class D : private B. Then the public and protected members of the base become private in the derived class. This access specifier can be used with every type of inheritance. It works in single with one base, in multiple with each base separately, and in hybrid too. No type blocks it. So the first three options are wrong, and the answer is that all types can have private inheritance.
प्रश्न 4उत्तर + हल
निम्नलिखित में से कौन मल्टीपल इनहेरिटेंस / मल्टीपाथ इनहेरिटेंस का सबसे अच्छा वर्णन है?
Which of the following best describes multiple inheritance/multipath inheritance?
  1. Aदो classes का किन्हीं अन्य classes का parent होनाTwo classes being parent of any other classes
  2. Bतीन classes का किसी भी class का parent होनाThree classes being parent of any classes
  3. Cएक से अधिक classes का एक ही child class का parent होनाMore than one class being parent of single child
  4. Dइनमें से कोई नहींNone of these

सही उत्तर / Answer: (C)

हल / Solution
Multiple इनहेरिटेंस में एक ही child class के एक से ज़्यादा parent यानी base classes होते हैं, जैसे class C : public A, public B। यहाँ ज़रूरी बात 'एक ही child' है। पहले विकल्प में दो classes किन्हीं दूसरी classes की parent हैं, पर यह नहीं कहा कि child एक ही है। दूसरे विकल्प में गिनती तीन पर बाँध दी गई है, जबकि दो parent भी काफ़ी हैं। इसलिए तीसरा विकल्प सबसे सटीक है।
In multiple inheritance, one single child class has more than one parent or base class, for example class C : public A, public B. The key point is that the child is the same one. The first option says two classes are parents of any other classes, but it does not say the child is the same. The second option fixes the count at three, while two parents are enough. So the third option is the most exact.
प्रश्न 5उत्तर + हल
कौन-सी प्रोग्रामिंग भाषा मल्टीपल इनहेरिटेंस (एकाधिक वंशानुक्रम) का समर्थन नहीं करती?
Which programming language does not support multiple inheritance?
  1. AC++ और JavaC++ and Java
  2. BC और C++C and C++
  3. CJava
  4. Dकोई नहींNone

सही उत्तर / Answer: (C)

हल / Solution
Java में एक class एक साथ दो classes को extend नहीं कर सकती, इसलिए वह multiple इनहेरिटेंस का समर्थन नहीं करती। वहाँ यह काम interfaces से होता है। C++ में multiple इनहेरिटेंस पूरी तरह चलता है, इसलिए जिन विकल्पों में C++ है वे ग़लत हैं। 'C और C++' वाला विकल्प भी इसी कारण ग़लत है। C तो object-oriented भाषा ही नहीं है, उसमें इनहेरिटेंस होता ही नहीं। इसलिए सही उत्तर Java है।
In Java a class cannot extend two classes at once, so Java does not support multiple inheritance. There the same job is done with interfaces. C++ fully supports multiple inheritance, so any option that includes C++ is wrong. The option C and C++ is wrong for this reason too. C is not even an object-oriented language, so it has no inheritance at all. So the correct answer is Java.
प्रश्न 6उत्तर + हल
इनहेरिटेंस का सही वाक्य-विन्यास (syntax) क्या है?
What is the correct syntax of inheritance?
  1. Aderived class : base class { }
  2. Bbase class : derived class { }
  3. Cderived class : derived class { }
  4. Dइनमें से कोई नहींNone of these

सही उत्तर / Answer: (A)

हल / Solution
इनहेरिटेंस लिखते समय पहले नई यानी derived class का नाम आता है, फिर colon (:) और उसके बाद base class का नाम। पूरा रूप class Derived : public Base { }; होता है, जिसमें public जैसा access specifier चाहें तो छोड़ भी सकते हैं। दूसरे विकल्प में क्रम उलटा है, base पहले लिखा है। तीसरे में दोनों तरफ़ derived class है, जिसका कोई अर्थ नहीं। इसलिए पहला विकल्प ही सही क्रम दिखाता है।
When writing inheritance, the name of the new derived class comes first, then a colon (:), and then the name of the base class. The full form is class Derived : public Base { }; where an access specifier like public may also be left out. The second option has the order reversed, with the base first. The third has derived class on both sides, which makes no sense. So the first option shows the right order.
प्रश्न 7उत्तर + हल
C++ में इनहेरिटेंस का उपयोग क्यों किया जाता है?
Why do we use inheritance in C++?
  1. Aकोड के उपयोग की क्षमता (use ability) के लिएFor the code use ability
  2. Bकोड की क्षमता (ability) के लिएFor the code ability
  3. Cकोड के पुनः उपयोग (reusability) के लिएFor the code reusability
  4. Dइनमें से कोई नहींNone of these

सही उत्तर / Answer: (C)

हल / Solution
इनहेरिटेंस का मुख्य मक़सद कोड का पुनः उपयोग (reusability) है। एक बार base class में data और functions लिख दिए, तो derived class उन्हें बिना दोबारा लिखे पा लेती है। इससे समय बचता है, ग़लतियाँ घटती हैं और पहले से जाँचा हुआ कोड फिर काम आता है। 'कोड के उपयोग की क्षमता' और 'कोड की क्षमता' जैसे विकल्पों का कोई तय अर्थ नहीं है। वे सिर्फ़ मिलते-जुलते शब्द हैं। इसलिए सही उत्तर reusability है।
The main purpose of inheritance is code reusability. Once data and functions are written in a base class, a derived class gets them without writing them again. This saves time, reduces mistakes and lets already tested code be used again. Options like code use ability and code ability have no fixed meaning. They are only look-alike words. So the correct answer is code reusability.
प्रश्न 8उत्तर + हल
कौन-सा इनहेरिटेंस Java में समर्थित नहीं है, पर C++ में समर्थित है?
Which inheritance is not supported by Java but is supported by C++?
  1. Aमल्टीलेवल इनहेरिटेंस (Multilevel)Multilevel inheritance
  2. Bमल्टीपल इनहेरिटेंस (Multiple)Multiple inheritance
  3. Cसिंगल लेवल इनहेरिटेंस (Single level)Single level inheritance
  4. Dये सभीAll of these

सही उत्तर / Answer: (B)

हल / Solution
C++ में एक class एक साथ कई classes से इनहेरिट कर सकती है, जैसे class C : public A, public B। इसे multiple इनहेरिटेंस कहते हैं। Java में classes के लिए यह सुविधा नहीं है, क्योंकि इससे डायमंड समस्या जैसी उलझन बनती है। Java में यह काम interfaces से किया जाता है। Single level और multilevel इनहेरिटेंस दोनों भाषाओं में चलते हैं, इसलिए वे और 'ये सभी' ग़लत हैं। सही उत्तर multiple इनहेरिटेंस है।
In C++ a class can inherit from several classes at once, like class C : public A, public B. This is called multiple inheritance. Java does not allow this for classes, because it causes confusion such as the diamond problem. In Java the same job is done with interfaces. Single level and multilevel inheritance work in both languages, so those options and All of these are wrong. The answer is multiple inheritance.
प्रश्न 9उत्तर + हल
यदि एक derived class के दो या दो से अधिक base class हों, तो इस प्रकार के इनहेरिटेंस को क्या कहते हैं?
If one derived class has two or more base classes, this type of inheritance is called?
  1. Aमल्टीलेवल इनहेरिटेंस (Multilevel)Multilevel inheritance
  2. Bहाइब्रिड इनहेरिटेंस (Hybrid)Hybrid inheritance
  3. Cमल्टीपल इनहेरिटेंस (Multiple)Multiple inheritance
  4. Dसिंगल लेवल इनहेरिटेंस (Single level)Single level inheritance

सही उत्तर / Answer: (C)

हल / Solution
जब एक ही derived class एक साथ दो या ज़्यादा base classes से इनहेरिट करती है, तो उसे multiple इनहेरिटेंस कहते हैं, जैसे class C : public A, public B। Multilevel में हर class का एक ही base होता है, पर classes सीढ़ी की तरह एक के नीचे एक बनती हैं। Single level में सिर्फ़ एक base होता है। Hybrid कई प्रकारों का मेल है। इसलिए दिए गए वर्णन पर सही उत्तर multiple इनहेरिटेंस है।
When one derived class inherits from two or more base classes at the same time, it is called multiple inheritance, for example class C : public A, public B. In multilevel inheritance each class has only one base, but classes form a chain one below another. Single level has just one base. Hybrid is a mix of several types. So for the given description the answer is multiple inheritance.
प्रश्न 10उत्तर + हल
सिंगल लेवल इनहेरिटेंस में कौन-सा संबंध बनता है?
Which relationship is formed in single level inheritance?
  1. AOr-A संबंधOr-A relationship
  2. BIs-A संबंधIs-A relationship
  3. CAnd-A संबंधAnd-A relationship
  4. Dये सभीAll of these

सही उत्तर / Answer: (B)

हल / Solution
सिंगल लेवल इनहेरिटेंस में एक derived class, एक base class से बनती है। derived class, base class का ही एक ख़ास रूप होती है, इसलिए इनके बीच Is-A संबंध बनता है। जैसे class Dog : public Animal में कहा जाता है कि Dog एक Animal है। Or-A और And-A जैसा कोई संबंध OOP में नहीं होता। ये सिर्फ़ भ्रम पैदा करने वाले विकल्प हैं, इसलिए 'ये सभी' भी ग़लत है। सही उत्तर Is-A है।
In single level inheritance, one derived class comes from one base class. The derived class is a special kind of the base class, so an Is-A relationship is formed. For example, with class Dog : public Animal we say a Dog is an Animal. There is no Or-A or And-A relationship in OOP. These are just made-up distractors, so All of these is also wrong. The answer is Is-A.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 12उत्तर app में
निम्नलिखित में से कौन-सा C++ में इनहेरिटेंस का प्रकार है?
Which of the following is a type of inheritance in C++?
  1. Aसिंगल लेवल इनहेरिटेंस (Single level)Single level inheritance
  2. Bमल्टी लेवल इनहेरिटेंस (Multi level)Multi level inheritance
  3. Cहाइब्रिड इनहेरिटेंस (Hybrid)Hybrid inheritance
  4. Dये सभीAll of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 13उत्तर app में
base class का कौन-सा public सदस्य इनहेरिट नहीं होता?
Which public member of a base class cannot be inherited?
  1. Aकंस्ट्रक्टर (Constructor)Constructor
  2. Bडिस्ट्रक्टर (Destructor)Destructor
  3. CA और B दोनोंBoth A & B
  4. Dकेवल BOnly B
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
निम्नलिखित प्रोग्राम का आउटपुट क्या है?

class A

{

public:

A(int x)

{

cout<<x; 

}

};

class B : public A

{

};

main()

{

B obj;

}
What is the output of the following program?

class A

{

public:

A(int x)

{

cout<<x; 

}

};

class B : public A

{

};

main()

{

B obj;

}
  1. Agarbage
  2. B0
  3. Cकुछ नहीं (nothing)nothing
  4. DError
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 15उत्तर app में
C++ में कोड की पुनः उपयोगिता (reusability) ______ से प्राप्त की जा सकती है।
Reusability of the code can be achieved in C++ through ______.
  1. Aबहुरूपता (Polymorphism)Polymorphism
  2. Bएनकैप्सुलेशन (Encapsulation)Encapsulation
  3. Cइनहेरिटेंस (Inheritance)Inheritance
  4. DA और C दोनोंBoth A and C
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 16उत्तर app में
class X, class Y और class Z तीनों एक ही class BASE से बनाई (derive की) गई हैं। यह ______ इनहेरिटेंस है।
Class X, class Y and class Z are derived from class BASE. This is ______ inheritance.
  1. Aमल्टीपल (Multiple)Multiple
  2. Bबहुस्तरीय (Multilevel)Multilevel
  3. Cपदानुक्रमित (Hierarchical)Hierarchical
  4. Dएकल (Single)Single
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?

class A

{

public:

int x;

};

class B : public A

{

};

int main()

{

B obj;

cout<<obj.x;

return 0;

}
What is the output of the following program?

class A

{

public:

int x;

};

class B : public A

{

};

int main()

{

B obj;

cout<<obj.x;

return 0;

}
  1. A0
  2. BGarbage (कोई अनिश्चित मान)Garbage
  3. CError
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
किस प्रकार के इनहेरिटेंस से डायमंड समस्या (diamond problem) पैदा होती है?
Which type of inheritance leads to the diamond problem?
  1. Aएकल स्तर (Single level)Single level
  2. Bबहुस्तरीय (Multi-level)Multi-level
  3. Cमल्टीपल (Multiple)Multiple
  4. Dपदानुक्रमित (Hierarchical)Hierarchical
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
C++ प्रोग्राम में इनहेरिटेंस से क्या संभव होता है?
What does inheritance allow in a C++ program?
  1. Aclass का पुनः उपयोग (Re-usability)Class Re-usability
  2. Bclasses का पदानुक्रम (hierarchy) बनानाCreating a hierarchy of classes
  3. Cविस्तार की सुविधा (Extendibility)Extendibility
  4. Dउपरोक्त सभीAll of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
Inheritance के सभी 20 प्रश्न — उत्तर, हल और अभ्यास

FliQi Question Bank app में topic-वार अभ्यास, कठिनाई-स्तर और आपकी प्रगति।

  • पहला test मुफ़्त
  • हिंदी + English
  • जाँचे हुए उत्तर और हल

यह topic किन परीक्षाओं में आता है

C++ Language के दूसरे topics

सभी topics