FliQi Education App Download
प्रश्न-बैंक · Dot Net

OOPs Concepts — प्रश्न और उत्तर

Dot Net · 24 जाँचे हुए (verified) प्रश्न

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

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

भाषा
प्रश्न 1उत्तर + हल
C# में object का valid syntax कौन-सा है?
Which is the valid syntax of an object in C#?
  1. Aclassname Ref. Variable = new class name ();
  2. Binterface name object = new object ();
  3. Cclassname = new class name ();
  4. Dये सभीAll of these

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

हल / Solution
C# में object बनाने का रूप है: ClassName refVariable = new ClassName(); बाईं ओर class का नाम और reference variable होता है, दाईं ओर new operator constructor को call करता है। विकल्प 2 में interface वाले variable को साधारण object बिना cast दिया जा रहा है, और object एक keyword है, इसलिए वह variable का नाम भी नहीं हो सकता। विकल्प 3 में variable का नाम ही ग़ायब है। इसलिए 'ये सभी' भी ग़लत है।
The C# syntax for creating an object is ClassName refVariable = new ClassName(); The left side gives the class type and a reference variable, and on the right the new operator calls the constructor. Option 2 assigns a plain object instance to an interface variable without a cast, and object is a keyword, so it cannot be a variable name. Option 3 has no variable name at all. So All of these is wrong.
प्रश्न 2उत्तर + हल
C# में this keyword किस class का reference रखता है?
In C#, the this keyword holds a reference of which class?
  1. AReference class
  2. BCurrent class
  3. COld class
  4. Dये सभीAll of these

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

हल / Solution
C# में this keyword उसी class के मौजूदा object (current instance) की ओर इशारा करता है, जिसके method या constructor में वह लिखा है। जैसे this.name = name में बाईं ओर वाला name object का field है और दाईं ओर वाला parameter। 'Reference class' और 'old class' जैसी कोई चीज़ C# में होती ही नहीं। इसलिए 'ये सभी' भी ग़लत है और सही उत्तर current class है।
In C#, the this keyword refers to the current instance of the class in whose method or constructor it is written. For example, in this.name = name, the left name is the object's field and the right name is the parameter. There is nothing called a reference class or an old class in C#, so All of these is wrong too. The answer is current class.
प्रश्न 3उत्तर + हल
निम्न में से कौन-सा constructor singleton class pattern को लागू (implement) करता है?
Which of the following constructors implements the singleton class pattern?
  1. AStatic
  2. BParameterized
  3. CPrivate
  4. DDefault

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

हल / Solution
Singleton pattern में पूरी application में class का सिर्फ़ एक object बनना चाहिए। इसके लिए constructor को private रखा जाता है, ताकि बाहर का code new से नया object न बना सके। Class ख़ुद एक static field में अपना इकलौता object रखती है और उसे किसी static property से देती है। Static, parameterized या default constructor अकेले बाहर से object बनना नहीं रोकते। इसलिए उत्तर private constructor है।
The singleton pattern allows only one object of a class in the whole application. To achieve this, the constructor is made private, so outside code cannot create new objects with new. The class keeps its single object in a static field and hands it out through a static property. A static, parameterized or default constructor alone does not stop outside creation. So the answer is the private constructor.
प्रश्न 4उत्तर + हल
C# में यदि किसी constructor को private access specifier के साथ बनाया जाए, तो वह क्या कहलाता है?
In C#, if a constructor is created with the private access specifier, it is known as?
  1. AStatic
  2. BCopy
  3. CPublic
  4. DPrivate

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

हल / Solution
जिस constructor के आगे private लिखा हो, उसे private constructor कहते हैं। ऐसी class का object class के बाहर से new द्वारा नहीं बनाया जा सकता। इसका उपयोग singleton pattern में और उन classes में होता है जिनमें सिर्फ़ static members हों। Static constructor static keyword से बनता है, copy constructor दूसरे object से मान लेता है, और public constructor बाहर से object बनने देता है। इसलिए उत्तर private है।
A constructor declared with the private access modifier is called a private constructor. Code outside the class cannot create an object of that class with new. It is used in the singleton pattern and in classes that contain only static members. A static constructor uses the static keyword, a copy constructor takes values from another object, and a public constructor allows outside creation. So the answer is Private.
प्रश्न 5उत्तर + हल
क्या C# में constructor पर access modifier का उपयोग कर सकते हैं?
Can you use an access modifier on a constructor in C#?
  1. AहाँYes
  2. BनहींNo
  3. CशायदMaybe
  4. Dइनमें से कोई नहींNone of these

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

हल / Solution
हाँ, C# में constructor पर public, private, protected और internal जैसे access modifier लगा सकते हैं। Public constructor से कहीं से भी object बन सकता है। Private constructor बाहर से object बनना रोकता है, जो singleton pattern में काम आता है। Protected constructor सिर्फ़ derived class को उसका उपयोग करने देता है। सिर्फ़ static constructor पर access modifier नहीं लगता। इसलिए उत्तर 'हाँ' है; 'नहीं' और 'शायद' ग़लत हैं।
Yes. In C#, a constructor can have access modifiers such as public, private, protected and internal. A public constructor lets objects be created from anywhere. A private constructor stops outside code from creating objects, which is used in the singleton pattern. A protected constructor lets only derived classes use it. Only the static constructor cannot take an access modifier. So the answer is Yes; No and Maybe are wrong.
प्रश्न 6उत्तर + हल
C# में क्या static constructor, parameterized constructor हो सकता है?
Can a static constructor be a parameterized constructor in C#?
  1. AहाँYes
  2. BनहींNo
  3. CशायदMaybe
  4. Dइनमें से कोई नहींNone of these

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

हल / Solution
C# में static constructor में कोई parameter नहीं हो सकता। इसे CLR ख़ुद एक ही बार चलाता है, जब class पहली बार इस्तेमाल होती है। हम इसे कभी सीधे call नहीं करते, इसलिए इसे argument देने का कोई रास्ता ही नहीं है। इस पर access modifier भी नहीं लगता। static Student(int x) लिखने पर compile error आता है। इसलिए उत्तर 'नहीं' है; 'हाँ' और 'शायद' ग़लत हैं।
In C#, a static constructor cannot have parameters. The CLR runs it automatically, only once, when the class is first used. We never call it directly, so there is no way to pass arguments to it. It cannot have an access modifier either. Writing static Student(int x) gives a compile error. So a static constructor can never be parameterized; the answer is No, and Yes and Maybe are wrong.
प्रश्न 7उत्तर + हल
C# में क्या constructor का कोई return type होता है?
Does a constructor have any return type in C#?
  1. AहाँYes
  2. BनहींNo
  3. CशायदMaybe
  4. Dइनमें से कोई नहींNone of these

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

हल / Solution
C# में constructor का कोई return type नहीं होता, void भी नहीं। उसका काम सिर्फ़ नए object को शुरुआती मान देना है; object तो new operator ख़ुद लौटाता है। अगर हम class के नाम वाले member के आगे void या int लिख दें, तो compiler error देता है कि member का नाम class के नाम जैसा नहीं हो सकता। इसलिए उत्तर 'नहीं' है; 'हाँ' और 'शायद' ग़लत हैं।
In C#, a constructor has no return type, not even void. Its only job is to initialise the new object; the new operator itself returns the object. If you write void or int before a member named after the class, the compiler gives an error saying member names cannot be the same as their enclosing type. So the answer is No, and Yes and Maybe are wrong.
प्रश्न 8उत्तर + हल
C# में constructor के साथ क्या नहीं किया जा सकता?
What cannot be done to a constructor in C#?
  1. AAbstract
  2. BFinal
  3. CSynchronized
  4. Dये सभीAll of these

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

हल / Solution
Constructor के साथ इनमें से कुछ भी नहीं किया जा सकता। Abstract का मतलब है बिना body का member, पर constructor को object बनाने के लिए body चाहिए और वह inherit भी नहीं होता। Final (C# में sealed) override रोकने के लिए है, पर constructor override होता ही नहीं। Synchronized Java का modifier है; C# में constructor पर ऐसा कोई keyword नहीं लगता। तीनों मना हैं, इसलिए सही उत्तर 'ये सभी' है।
None of these can be applied to a constructor. Abstract means a member without a body, but a constructor needs a body to build the object and is never inherited. Final (sealed in C#) exists to stop overriding, but constructors are never overridden. Synchronized is a Java modifier; C# has no such keyword for constructors. Since all three are not allowed, the answer is All of these.
प्रश्न 9उत्तर + हल
C# में constructor का नाम किसके नाम के समान होना आवश्यक है?
In C#, the name of a constructor must be the same as the name of the?
  1. AVariable
  2. BObject
  3. CMethod
  4. DClass

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

हल / Solution
C# में constructor का नाम ठीक वही होना चाहिए जो उसकी class का नाम है, जैसे class Student का constructor Student() होगा। इसी से compiler पहचानता है कि यह साधारण method नहीं, constructor है। Constructor का नाम किसी variable या object के नाम पर नहीं रखा जाता। कोई दूसरा नाम रखने पर वह constructor नहीं रहता, बल्कि return type माँगने वाला साधारण method माना जाता है। इसलिए उत्तर class है।
In C#, a constructor must have exactly the same name as its class. For example, the constructor of class Student is Student(). This is how the compiler knows it is a constructor and not an ordinary method. A constructor is not named after a variable or an object. If you give it any other name, the compiler treats it as a normal method and asks for a return type. So the answer is class.
प्रश्न 10उत्तर + हल
C# में class का वह विशेष method, जो class का instance बनते ही अपने-आप invoke हो जाता है, क्या कहलाता है?
In C#, a special method of a class that is invoked automatically when an instance of the class is created is known as?
  1. AObject
  2. BConstructor
  3. CMethod
  4. Dइनमें से कोई नहींNone of these

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

हल / Solution
Constructor class का विशेष method है। new से object बनते ही यह अपने-आप चलता है और object के fields को शुरुआती मान देता है। इसका नाम class के नाम जैसा होता है और इसका कोई return type नहीं होता। Object ख़ुद instance है, method नहीं। साधारण method को हमें ख़ुद call करना पड़ता है, वह अपने-आप नहीं चलता। इसलिए सही उत्तर constructor है और 'इनमें से कोई नहीं' ग़लत है।
A constructor is a special method of a class. It runs automatically as soon as an object is created with new and gives the object's fields their starting values. It has the same name as the class and no return type. An object is the instance itself, not a method. An ordinary method must be called explicitly; it does not run on its own. So the answer is Constructor, and None of these is wrong.
आगे के 14 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 24उत्तर app में
कौन-सा तत्व डेवलपर्स को सारी कार्यक्षमता एक अनोखे, application-विशेष नाम के अंदर समेटने देता है?
Which allows developers to bundle all functionality under a unique, application-specific name?
  1. AClass
  2. BNamespace
  3. CObject
  4. DProperty
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
OOPs Concepts के सभी 24 प्रश्न — उत्तर, हल और अभ्यास

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

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

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

Dot Net के दूसरे topics

सभी topics