C++ में किसी class के data members और member functions डिफ़ॉल्ट रूप से private होते हैं। सही या ग़लत?
Data members and member functions of a class are private by default in C++. True or False?
- AसहीTrue
- Bग़लतFalse
- Ccode पर निर्भर करता हैDepends on the code
- Dcompiler पर निर्भर करता हैDepends on the compiler
सही उत्तर / Answer: (A)
हल / Solution
C++ में class के अंदर लिखे members पर अगर कोई access specifier न लगाया जाए, तो data members और member functions दोनों अपने आप private होते हैं। इसलिए कथन सही है। यह नियम भाषा ने तय किया है, इसलिए यह न code पर निर्भर है और न compiler पर। हाँ, programmer चाहे तो public या protected लिखकर इसे बदल सकता है। ध्यान दीजिए कि struct में default access public होता है, private नहीं।
In C++, if no access specifier is written for members inside a class, both the data members and the member functions are private by default. So the statement is true. This rule is fixed by the language, so it depends neither on the code nor on the compiler. The programmer can of course change it by writing public or protected. Note that in a struct the default access is public, not private.
यदि 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?
- A~A() फिर ~B() फिर ~C()~A() then ~B() then ~C()
- B~C() फिर ~A() फिर ~B()~C() then ~A() then ~B()
- C~C() फिर ~B() फिर ~A()~C() then ~B() then ~A()
- 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.
C++ भाषा ………… object-oriented भाषा है।
The C++ language is a ………… object-oriented language.
- Aपूरी तरह (pure) object orientedPure object oriented
- Bobject oriented नहींNot object oriented
- Cआंशिक (semi) object-orientedSemi object-oriented
- Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (C)
हल / Solution
C++ को semi या partial object-oriented भाषा कहा जाता है। इसमें class, object, inheritance और polymorphism जैसी सारी OOP सुविधाएँ हैं, इसलिए यह 'object oriented नहीं' वाली भाषा नहीं है। पर इसमें बिना class के भी प्रोग्राम लिखा जा सकता है। main() फ़ंक्शन class के बाहर रहता है, global variable बन सकते हैं और friend function private डेटा छू सकता है। इसलिए यह pure object oriented भी नहीं है। सही उत्तर semi object-oriented है।
C++ is called a semi or partial object-oriented language. It has all the OOP features such as classes, objects, inheritance and polymorphism, so it is not a non object-oriented language. But a program can also be written without any class. The main() function stays outside a class, global variables are allowed and a friend function can reach private data. So it is not purely object oriented either. The answer is semi object-oriented.
निम्नलिखित में से कौन polymorphism को दर्शाता है?
Which of the following explains polymorphism?
- Aint func(int, int); float func1(float, float);
- Bint func(int); int func(int);
- Cint func(float); float func(int, int, char);
- Dint func(); int new_func();
सही उत्तर / Answer: (C)
हल / Solution
Function overloading में एक ही नाम के फ़ंक्शन होते हैं, पर उनकी parameter list अलग होती है। यही compile time polymorphism है। विकल्प 3 में दोनों का नाम func है और parameters अलग हैं: एक में float, दूसरे में int, int, char। इसलिए यह overloading है। विकल्प 1 और 4 में नाम ही अलग हैं (func, func1, new_func)। विकल्प 2 में दोनों घोषणाएँ बिलकुल एक जैसी हैं, यानी वही फ़ंक्शन दोबारा घोषित हुआ, कोई नया रूप नहीं बना।
Function overloading means functions share one name but have different parameter lists. This is compile time polymorphism. In option 3 both functions are named func, and their parameters differ: one takes a float, the other takes int, int, char. So it is overloading. Options 1 and 4 use different names (func, func1, new_func). In option 2 both declarations are exactly the same, so the same function is only declared twice and no new form is created.
C++ में आउटपुट के लिए किस विधि का उपयोग किया जाता है?
Which method is used for output in C++?
- ACout <<
- Bcout >>
- Ccout <<
- Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (C)
हल / Solution
सही विकल्प : (C) cout <<
आउटपुट के लिए cout के साथ insertion operator << लगाया जाता है, जैसे cout << x; यह operator मान को आउटपुट stream में डालता है, जो screen पर दिखता है। >> extraction operator है, जो cin के साथ इनपुट में आता है। इसलिए cout >> ग़लत है। 'Cout <<' में C बड़ा लिखा है, और C++ case sensitive है, इसलिए यह भी ग़लत है। object हमेशा छोटे अक्षरों में cout ही लिखा जाता है।
Correct option : (C) cout <<
For output, cout is used with the insertion operator <<, as in cout << x; This operator puts the value into the output stream, which appears on the screen. The >> symbol is the extraction operator, used with cin for input, so cout >> is wrong. 'Cout <<' has a capital C, and C++ is case sensitive, so it is also wrong. The object is always written in lower case as cout.
C++ क्या है?
C++ is
- Aप्रक्रियात्मक (procedural) प्रोग्रामिंग भाषाprocedural programming language
- Bऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग भाषाobject oriented programming language
- Cफ़ंक्शनल प्रोग्रामिंग भाषाfunctional programming language
- Dप्रक्रियात्मक और ऑब्जेक्ट ओरिएंटेड, दोनोंboth procedural and object oriented programming language
सही उत्तर / Answer: (D)
हल / Solution
C++ को बहु-प्रतिमान (multi-paradigm) भाषा कहा जाता है। यह C के ऊपर बनी है, इसलिए फ़ंक्शन और संरचनात्मक कोड वाली पुरानी प्रक्रियात्मक शैली इसमें ज्यों की त्यों चलती है। साथ ही इसमें क्लास, ऑब्जेक्ट, वंशानुक्रम और बहुरूपता भी जोड़े गए, जिससे ऑब्जेक्ट ओरिएंटेड शैली भी पूरी तरह चलती है। इसीलिए पहला या दूसरा विकल्प अकेला अधूरा है। फ़ंक्शनल भाषा इसे नहीं कहते, वह अलग प्रतिमान है।
C++ is called a multi paradigm language. It was built on top of C, so the older procedural style with plain functions and structures still works exactly as before. On top of that it added classes, objects, inheritance and polymorphism, which makes the object oriented style fully available too. That is why option 1 or option 2 alone is incomplete. C++ is not classed as a functional language.
निम्नलिखित में से कौन-सी विशेषता OOPs की अवधारणा के अंतर्गत नहीं आती?
Which among the following features does not come under the concept of OOPs?
- Aडेटा बाइंडिंग (Data binding)Data binding
- Bडेटा हाइडिंग (Data hiding)Data hiding
- Cप्लेटफ़ॉर्म स्वतंत्रता (Platform independent)Platform independent
- Dमैसेज पासिंग (Message passing)Message passing
सही उत्तर / Answer: (C)
हल / Solution
प्लेटफ़ॉर्म स्वतंत्रता किसी भाषा के चलने के ढंग की बात है, OOPs की अवधारणा नहीं। जावा प्लेटफ़ॉर्म स्वतंत्र है और C++ नहीं, जबकि दोनों ही ऑब्जेक्ट ओरिएंटेड हैं — इसी से बात साफ़ हो जाती है। डेटा बाइंडिंग का मतलब डेटा और मेथड को एक क्लास में बाँधना यानी इनकैप्सुलेशन है। डेटा हाइडिंग पहुँच-नियंत्रक से होती है, और मैसेज पासिंग में ऑब्जेक्ट एक-दूसरे के मेथड बुलाते हैं।
Platform independence describes how a language is executed; it is not an object oriented concept. Java is platform independent and C++ is not, yet both are object oriented languages, which settles the matter. Data binding means tying data and methods together inside a class, that is encapsulation. Data hiding is achieved through access modifiers, and message passing is one object calling the methods of another.