पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
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.
प्रश्न 2उत्तर + हल
scope resolution operator पहचानिए।
Identify the scope resolution operator.
A:
B::
C?:
Dइनमें से कोई नहींNone
सही उत्तर / Answer: (B)
हल / Solution
C++ में scope resolution operator :: है। इससे बताया जाता है कि कोई नाम किस class या namespace का है। जैसे class के बाहर function define करते समय void A::show() लिखते हैं, और std::cout में cout को std namespace से लिया जाता है। अकेला : inheritance में और access specifier के बाद लगता है, जैसे class B : public A। ?: conditional यानी ternary operator है। इसलिए सही उत्तर :: है।
In C++, the scope resolution operator is ::. It tells which class or namespace a name belongs to. For example, a member function is defined outside the class as void A::show(), and std::cout takes cout from the std namespace. A single : is used in inheritance and after access specifiers, as in class B : public A. ?: is the conditional or ternary operator. So the correct answer is ::.
प्रश्न 3उत्तर + हल
constructor का implicit (अंतर्निहित) return type क्या है?
What is the implicit return type of a constructor?
Aकोई return type नहींNo return type
Bउसी class का object जिसमें वह define हैA class object in which it is defined
Cvoid
Dइनमें से कोई नहींNone
सही उत्तर / Answer: (B)
हल / Solution
constructor घोषित करते समय कोई return type नहीं लिखा जाता, void भी नहीं। यानी उसका कोई explicit return type नहीं है। पर प्रश्न implicit return type पूछ रहा है। constructor का काम उसी class का object बनाकर तैयार करना है, इसलिए उसका नतीजा उसी class का object माना जाता है। इसी अर्थ में विकल्प 2 सही है। 'कोई return type नहीं' घोषणा के बारे में है, implicit type के बारे में नहीं। void लिखना तो error देगा।
When a constructor is declared, no return type is written, not even void, so it has no explicit return type. But the question asks about the implicit return type. The job of a constructor is to build and ready an object of its own class, so its result is treated as an object of that class. In this sense option 2 is correct. No return type describes the declaration, not the implicit type, and writing void gives an error.
प्रश्न 4उत्तर + हल
Output बताइए।
#include <iostream>
using namespace std;
class A{
private:
int a;
public:
A(){
a=20;
cout<<"Default Constructor Called\n";
}
A(int x)
{
a=x;
cout<<"Parameterized Constructor Called";
}
};
int main() {
A obj1, obj2(3);
return 0;
}
Specify the output.
#include <iostream>
using namespace std;
class A{
private:
int a;
public:
A(){
a=20;
cout<<"Default Constructor Called\n";
}
A(int x)
{
a=x;
cout<<"Parameterized Constructor Called";
}
};
int main() {
A obj1, obj2(3);
return 0;
}
AParameterized constructor
BDefault constructor
CA और B दोनोंBoth A and B
DCompile time error
सही उत्तर / Answer: (C)
हल / Solution
main में पहले obj1 बनता है। इसके साथ कोई argument नहीं है, इसलिए default constructor A() चलता है और 'Default Constructor Called' छपता है, फिर नई पंक्ति आती है। उसके बाद obj2(3) बनता है, जिसमें एक int argument है। इसलिए A(int x) चलता है और 'Parameterized Constructor Called' छपता है। दोनों constructors के संदेश इसी क्रम में छपते हैं, इसलिए विकल्प 3 सही है। code में कोई ग़लती नहीं है, इसलिए compile error नहीं आता।
In main, obj1 is created first. It has no argument, so the default constructor A() runs and prints Default Constructor Called, followed by a new line. Then obj2(3) is created with one int argument, so A(int x) runs and prints Parameterized Constructor Called. Messages from both constructors are printed, in this order, so option 3 is correct. The code has no mistake, so there is no compile error.
प्रश्न 5उत्तर + हल
निम्न में से कौन-सा विकल्प friend class को सबसे अच्छा दर्शाता है?
Which of the following options best illustrates a friend class?
Aयह उस class के सभी private members को access और बदल सकती है जिसने इसे friend बनाया हैThis class can access and manipulate all the private members of the class that makes it a friend
Bfriend class उस class के केवल protected data members को access और बदल सकती हैA friend class can only access and manipulate the protected data members of that class
Cfriend class दूसरी class के किसी data member को access नहीं कर सकती, पर उसके methods use कर सकती हैA friend class cannot access any data member of another class but can use its methods
Dfriend class का कोई implementation नहीं होताA friend class does not have any implementation
सही उत्तर / Answer: (A)
हल / Solution
जब class A के अंदर friend class B; लिखा जाता है, तो B, A की friend class बन जाती है। अब B के member functions, A के private और protected members को access कर सकते हैं। इसलिए विकल्प 1 सही है। पहुँच सिर्फ़ protected तक सीमित नहीं है, इसलिए विकल्प 2 ग़लत है। friend class data members भी पढ़ सकती है, इसलिए विकल्प 3 ग़लत है। friend class का अपना implementation होता है।
When friend class B; is written inside class A, B becomes a friend class of A. Now all member functions of B can access and change the private and protected members of A. So option 1 is correct. The access is not limited to protected members, so option 2 is wrong. A friend class can read data members too, so option 3 is wrong. A friend class has its own implementation, so option 4 is wrong.
प्रश्न 6उत्तर + हल
डेटा और कोड के अब्स्ट्रक्शन के संयोजन को भौतिक रूप से ________ द्वारा दर्शाया जाता है।
The combination of abstraction of the data and code is physically represented by ________.
AइनहेरिटेंसInheritance
Bऑब्जेक्टObject
Cक्लासClass
Dइंटरफ़ेसInterfaces
सही उत्तर / Answer: (B)
हल / Solution
class में data और code का abstraction लिखा जाता है, पर class खुद केवल एक खाका है और memory में कोई असली रूप नहीं लेती। जब उस class से object बनता है, तभी data और functions का यह मेल memory में सचमुच मौजूद होता है। इसलिए object को इस संयोजन का भौतिक रूप कहा जाता है। inheritance एक class से दूसरी class बनाना है। interface सिर्फ़ functions का नियम बताता है। सही उत्तर ऑब्जेक्ट है।
A class describes the abstraction of data and code, but a class is only a blueprint and has no real form in memory. When an object is created from that class, the combination of data and functions actually exists in memory. So the object is called the physical representation of this combination. Inheritance means creating one class from another. An interface only lists rules for functions. So the answer is object.
प्रश्न 7उत्तर + हल
यदि उपयोगकर्ता code में classes का उपयोग नहीं करता, तो निम्नलिखित में से किस सुविधा का उल्लंघन हो सकता है?
Which of the following features may be violated if the user does not use classes in the code?
A'object का उपयोग ज़रूरी है' वाला नियम टूटता हैThe rule that objects must be used is violated
Bकेवल encapsulation का उल्लंघन होता हैOnly the encapsulation concept is violated
Cinheritance लागू नहीं हो सकताInheritance cannot be implemented
Dमूल रूप से OOP की सभी सुविधाएँ टूट जाती हैंBasically, all the features of OOPS get violated
सही उत्तर / Answer: (D)
हल / Solution
OOP की सारी सुविधाएँ class पर टिकी हैं। object class से ही बनता है। encapsulation में data और functions class के अंदर बँधते हैं। inheritance एक class से दूसरी class बनाता है, और polymorphism भी class hierarchy में काम करता है। इसलिए class के बिना इनमें से कोई सुविधा लागू नहीं होती। विकल्प 1, 2 और 3 हर एक सिर्फ़ एक हिस्से की बात करते हैं, जबकि असल में सब टूटता है। इसलिए विकल्प 4 सही है।
All OOP features depend on classes. Objects are created from a class. Encapsulation binds data and functions inside a class. Inheritance builds one class from another, and polymorphism also works through a class hierarchy. So without classes, none of these features can be applied properly. Options 1, 2 and 3 each mention only one part, while in fact everything is lost. So option 4 is correct.
प्रश्न 8उत्तर + हल
निम्नलिखित में से कौन-सा syntax class definition के लिए ग़लत है?
Which of the following syntax is incorrect for the class definition?
Astudent class{ };
Bclass student{ student(int a){} };
Cclass teacher{ public: teacher(int a){ } };
Dइनमें से कोई नहींNone of the mentioned
सही उत्तर / Answer: (A)
हल / Solution
class definition में पहले keyword class आता है, फिर class का नाम, फिर braces और अंत में semicolon। student class{ }; में नाम पहले और keyword बाद में है, इसलिए यह ग़लत syntax है। विकल्प 2 में constructor private हिस्से में है, फिर भी syntax सही है, बस बाहर से object बनाना मुश्किल होगा। विकल्प 3 पूरी तरह सही है। एक ग़लत syntax मौजूद है, इसलिए 'इनमें से कोई नहीं' भी ग़लत है। सही उत्तर विकल्प 1 है।
A class definition starts with the keyword class, then the class name, then braces, and ends with a semicolon. In student class{ }; the name comes first and the keyword after it, so the syntax is wrong. In option 2 the constructor is private, but the syntax is still valid. Option 3 is fully correct. Since one wrong syntax exists, None of the mentioned is also wrong. So the answer is option 1.
प्रश्न 9उत्तर + हल
एक class का आकार (size) क्या होता है?
What is the size of a class?
Aउसी class के variables के साथ सभी inherited variables के आकार का योगSum of the size of all inherited variables along with the variables of the same class
Bउसी class के सबसे बड़े variable का आकारThe size of the largest variable of the same class
Cprogramming भाषाओं में classes का कोई आकार नहीं होताClasses in programming languages do not have any size
Dclass के अंदर के सभी variables के आकार का योगSum of the size of all the variables within a class
सही उत्तर / Answer: (C)
हल / Solution
class सिर्फ़ एक खाका (blueprint) है। उसे घोषित करने से memory नहीं मिलती, इसलिए class का अपना कोई आकार नहीं होता। memory तब मिलती है जब उसका object बनता है। sizeof(ClassName) लिखने पर भी असल में उसके एक object का आकार ही मिलता है। विकल्प 1 और 4 object के आकार की बात करते हैं, class की नहीं, और उसमें padding भी जुड़ सकती है। सबसे बड़े member का आकार union पर लागू होता है। इसलिए विकल्प 3 सही है।
A class is only a blueprint. Declaring it does not reserve memory, so a class itself has no size. Memory is given only when an object of the class is created. Even sizeof(ClassName) actually gives the size of one object of that class. Options 1 and 4 describe the size of an object, not of the class, and padding can also be added. The size of the largest member applies to a union. So option 3 is correct.
प्रश्न 10उत्तर + हल
निम्नलिखित में से किस class को generic class के रूप में जाना जाता है?
Which of the following classes is known as the generic class?
AFinal class
BTemplate class
CAbstract class
DEfficient code
सही उत्तर / Answer: (B)
हल / Solution
template class ऐसी class है जो किसी एक data type से बंधी नहीं होती। जैसे template <class T> class Box में T की जगह int, float या कोई भी type रखा जा सकता है। एक ही code कई types पर चलता है, इसलिए यह generic class है। abstract class में कम से कम एक pure virtual function होता है। final class से आगे inheritance नहीं होता। Efficient code class का प्रकार ही नहीं है। इसलिए विकल्प 2 सही है।
A template class is a class that is not tied to one data type. For example, in template <class T> class Box, T can be replaced by int, float or any other type. The same code works for many types, so it is called a generic class. An abstract class has at least one pure virtual function. A final class cannot be inherited further. Efficient code is not a kind of class at all. So option 2 is correct.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
निम्नलिखित में से कौन-सी भाषा classes का उपयोग करती है लेकिन polymorphism की अवधारणा का नहीं?
Which of the following languages uses classes but not the polymorphism concept?
AProcedure oriented भाषाProcedure oriented language
BObject-based भाषाObject-based language
CClass-based भाषाClass-based language
Dयदि classes उपयोग होती हैं, तो programming भाषा में polymorphism भी हमेशा उपयोग होगाIf classes are used, then the polymorphism concept will always be used in the programming language