पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
Method overriding कैसे प्राप्त (achieve) की जाती है?
How is method overriding achieved?
AArguments की संख्या समान होनी चाहिएMust be similar number of arguments
BArguments का क्रम समान होना चाहिएMust be similar sequence of arguments
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (C)
हल / Solution
overriding में derived class का method, base class के method जैसा ही होना चाहिए। नाम वही, return type वही, parameter की संख्या वही और उनका type व क्रम भी वही। अगर संख्या या क्रम बदल गया तो वह override नहीं, नया overload बन जाता है और compiler override पर error देता है। इसलिए संख्या और क्रम दोनों का समान होना ज़रूरी है। सिर्फ़ एक शर्त काफ़ी नहीं, इसलिए विकल्प 1 और 2 अकेले अधूरे हैं।
In overriding, the derived class method must match the base class method. The name, return type, number of parameters, and their types and order must all be the same. If the number or order changes, it becomes a new overload, not an override, and the compiler reports an error on the override keyword. So both the number and the order must match. One condition alone is not enough, so options 1 and 2 alone are incomplete.
प्रश्न 2उत्तर + हल
Method overriding प्राप्त (achieve) करने के लिए किस प्रकार की Relationship बनानी होती है?
What kind of relationship has to be created to achieve method overriding?
AAS-A Relationship
BIS-A Relationship
CHAS-A Relationship
Dइनमें से सभीAll of these
सही उत्तर / Answer: (B)
हल / Solution
method overriding के लिए derived class को base class से inherit करना पड़ता है, तभी वह base का virtual method override कर सकती है। inheritance को ही IS-A relationship कहते हैं, जैसे Dog IS-A Animal। HAS-A relationship में एक class दूसरी class का object अपने अंदर रखती है, जैसे Car HAS-A Engine। उसमें inheritance नहीं होता, इसलिए override भी नहीं होता। AS-A कोई relationship नहीं है, इसलिए 'इनमें से सभी' भी ग़लत है।
For method overriding, the derived class must inherit from the base class; only then can it override a virtual method of the base. Inheritance is the IS-A relationship, like Dog IS-A Animal. In a HAS-A relationship, one class keeps an object of another class inside it, like Car HAS-A Engine. There is no inheritance there, so no overriding either. AS-A is not a relationship, so All of these is wrong too.
प्रश्न 3उत्तर + हल
जब किसी Child class का object, Parent class के reference variable में रखा (assign किया) जाता है, तो वह क्या कहलाता है?
When the object of a child class is assigned to a reference variable of the parent class, it is called
AUp casting
BObject casting
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (C)
हल / Solution
जैसे Animal a = new Dog(); में Dog का object, Animal के reference में रखा गया है। class के क्रम में यह नीचे से ऊपर की ओर जाना है, इसलिए इसे up casting कहते हैं। यह object यानी reference type की casting है, primitive type की नहीं, इसलिए इसे object casting भी कहा जाता है। यानी दोनों नाम इस पर लागू होते हैं और 'A और B दोनों' उत्तर है। C# में यह अपने आप हो जाती है।
In Animal a = new Dog(); a Dog object is stored in an Animal reference. This moves up the class hierarchy, from child to parent, so it is called up casting. It is a cast of an object, that is a reference type, not a primitive type, so it is also called object casting. Both names apply, so Both A and B is the answer. In C#, this cast happens automatically without writing it.
प्रश्न 4उत्तर + हल
Method overriding किस प्रकार के polymorphism में होती है?
Method overriding occurs in which type of polymorphism?
ARun time
BCompile time
CUser time
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (A)
हल / Solution
method overriding में base class का virtual method derived class में उसी signature के साथ override होता है। जब base class के reference से method बुलाया जाता है, तो कौन-सा version चलेगा यह program चलते समय असली object देखकर तय होता है। इसलिए overriding run time polymorphism है। compile time polymorphism overloading से होता है। User time नाम का कोई polymorphism नहीं है, इसलिए विकल्प 2, 3 और 4 ग़लत हैं।
In method overriding, a virtual method of the base class is overridden in the derived class with the same signature. When the method is called through a base class reference, the version that runs is decided while the program runs, by looking at the actual object. So overriding is run time polymorphism. Compile time polymorphism comes from overloading. There is no user time polymorphism, so options 2, 3 and 4 are wrong.
प्रश्न 5उत्तर + हल
Late binding किस polymorphism द्वारा दर्शाई (represent की) जाती है?
Late binding is represented by which polymorphism?
ACompile time polymorphism
BRun time polymorphism
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (B)
हल / Solution
late binding में यह फ़ैसला program चलते समय होता है कि कौन-सा method चलेगा। जैसे Shape s = new Circle(); s.Draw(); में reference Shape का है, पर Draw() Circle वाला चलता है, क्योंकि object Circle का है। यह virtual और override से होता है और इसे run time polymorphism कहते हैं। compile time polymorphism early binding है, जैसे overloading। इसलिए विकल्प 1 और 'A और B दोनों' ग़लत हैं।
In late binding, the decision about which method to call is made while the program runs. For example, in Shape s = new Circle(); s.Draw(); the reference is Shape, but the Circle version of Draw() runs because the object is a Circle. This works through virtual and override and is called run time polymorphism. Compile time polymorphism is early binding, like overloading. So option 1 and Both A and B are wrong.
प्रश्न 6उत्तर + हल
यदि किसी method को अलग-अलग signature के साथ declare किया जाए, तो वह क्या कहलाता है?
If a method is declared with different signatures, it is called
AMethod overriding
BMethod overloading
CMethod overlap
Dइनमें से सभीAll of these
सही उत्तर / Answer: (B)
हल / Solution
signature में method का नाम और parameter की संख्या, type और क्रम आते हैं। जब एक ही नाम के कई methods अलग-अलग parameter के साथ लिखे जाएँ, तो वह method overloading है, जैसे Show(int) और Show(string)। method overriding में signature बिलकुल वही रहता है, बस derived class body बदल देती है। Method overlap नाम का कोई concept नहीं है, इसलिए 'इनमें से सभी' भी ग़लत है।
A signature includes the method name and the number, type and order of its parameters. When several methods with the same name are written with different parameters, it is method overloading, like Show(int) and Show(string). In method overriding the signature stays exactly the same, and only the derived class changes the body. Method overlap is not a real concept, so All of these is also wrong.
प्रश्न 7उत्तर + हल
Early binding किस polymorphism को दर्शाता (represent करता) है?
Which polymorphism does early binding represent?
ARun time
BCompile time
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (B)
हल / Solution
binding का मतलब है method की call को उसकी असली body से जोड़ना। early binding में यह जोड़ compiler कोड बनाते समय ही कर देता है, program चलने से पहले। इसलिए यह compile time polymorphism है, जैसे method overloading में होता है। इसके उलट late binding में फ़ैसला program चलते समय object देखकर होता है, वह run time polymorphism है। इसलिए विकल्प 1 और 'A और B दोनों' ग़लत हैं।
Binding means linking a method call to its actual body. In early binding, the compiler makes this link while building the code, before the program runs. So it is compile time polymorphism, as in method overloading. In contrast, late binding makes the decision while the program runs, by looking at the actual object, and that is run time polymorphism. So option 1 and Both A and B are wrong.
प्रश्न 8उत्तर + हल
Method overloading किस polymorphism को दर्शाता (represent करता) है?
Which polymorphism does method overloading represent?
ARun time
BCompile time
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (B)
हल / Solution
method overloading में एक ही नाम के कई methods होते हैं, पर उनके parameter की संख्या या type अलग होते हैं। जैसे Add(int, int) और Add(double, double)। कौन-सा method चलेगा, यह compiler arguments देखकर कोड बनाते समय ही तय कर देता है। इसलिए यह compile time polymorphism है। Run time polymorphism method overriding से होता है, overloading से नहीं। इसलिए विकल्प 1 और 'A और B दोनों' ग़लत हैं।
In method overloading, there are several methods with the same name, but with a different number or type of parameters, like Add(int, int) and Add(double, double). The compiler looks at the arguments and decides which method to call while building the code. So it is compile time polymorphism. Run time polymorphism comes from method overriding, not overloading. So option 1 and Both A and B are wrong.
प्रश्न 9उत्तर + हल
Polymorphism कितने प्रकार का होता है?
How many types of polymorphism are there?
A3
B2
C5
D4
सही उत्तर / Answer: (B)
हल / Solution
Polymorphism के दो प्रकार हैं। पहला compile time polymorphism, जिसे static या early binding भी कहते हैं। यह method overloading और operator overloading से मिलता है। दूसरा run time polymorphism, जिसे dynamic या late binding भी कहते हैं। यह virtual और override के साथ method overriding से मिलता है। इसलिए उत्तर 2 है। 3, 4 या 5 गिनने के लिए कोई और मानक प्रकार नहीं है।
Polymorphism has two types. The first is compile time polymorphism, also called static polymorphism or early binding. It comes from method overloading and operator overloading. The second is run time polymorphism, also called dynamic polymorphism or late binding. It comes from method overriding with virtual and override. So the answer is 2. There is no other standard type to make the count 3, 4 or 5.
प्रश्न 10उत्तर + हल
एक ही action का कई रूपों में किया जाना क्या कहलाता है?
A single action performed in many forms is called
AInheritance
BInterface
CPolymany
DPolymorphism
सही उत्तर / Answer: (D)
हल / Solution
Polymorphism दो ग्रीक शब्दों से बना है: poly यानी कई और morph यानी रूप। यानी एक ही नाम का काम अलग-अलग हालात में अलग तरह से होना। जैसे Draw() method circle के लिए गोला बनाए और square के लिए चौकोर। C# में यह overloading और overriding से मिलता है। Inheritance गुण सौंपने का तरीक़ा है और interface methods का ढाँचा है। Polymany नाम का कोई concept नहीं है।
Polymorphism comes from two Greek words: poly means many and morph means form. It means one action with the same name behaves differently in different situations. For example, a Draw() method draws a circle for a Circle and a square for a Square. In C#, this comes from overloading and overriding. Inheritance is a way of passing on features, and an interface is an outline of methods. Polymany is not a real concept.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति