FliQi Education App Download
प्रश्न-बैंक · Programmer Java

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

Programmer Java · 35 जाँचे हुए (verified) प्रश्न

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

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

भाषा
प्रश्न 1उत्तर + हल

 

नीचे दिए गए जावा प्रोग्राम में, क्लास Circle इंटरफ़ेस Shape को लागू करता है। यहाँ कौन सी बहुरूपता अवधारणा लागू की गई है? interface Shape {     void area(); } class Circle implements Shape {     public void area() {     } }
In the java program given below, the class Circle implements the interface Shape. Which polymorphism concept has been applied here? interface Shape {     void area(); } class Circle implements Shape {     public void area() {     } }
  1. Aमेथड ओवरलोडिंगMethod overloading
  2. Bमेथड ओवरराइडिंगMethod overriding
  3. Cकोई बहुरूपता नहींNo polymorphism
  4. D(A) और (B) दोनोंBoth (A)&(B)

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

हल / Solution
इंटरफ़ेस Shape में area() केवल घोषित है, उसका शरीर नहीं है। Circle उसे लागू करते समय area() का अपना शरीर लिखती है, यानी ऊपर वाली घोषणा की जगह अपना रूप दे देती है। यही मेथड ओवरराइडिंग है और यह रनटाइम बहुरूपता का उदाहरण बनता है। ओवरलोडिंग यहाँ है ही नहीं, क्योंकि area() का नाम एक बार ही आया है और उसके पैरामीटर भी नहीं बदले। इसलिए न तीसरा विकल्प ठीक है, न दोनों वाला चौथा।
In the interface Shape the method area() is only declared and has no body. When Circle implements the interface, it supplies its own body for area(), so it replaces the declaration above with a real form. That is method overriding, and it is an example of runtime polymorphism. There is no overloading here, because the name area() appears only once and its parameter list has not been changed. So neither the third option nor the fourth option can be correct.
प्रश्न 2उत्तर + हल

 

जावा में बहुरूपता (polymorphism) के अंतर्गत कौन सी अवधारणाएँ आती हैं?
What concepts come under polymorphism in Java?
  1. Aमेथड ओवरलोडिंगMethod overloading
  2. Bकंस्ट्रक्टर ओवरलोडिंगConstructor overloading
  3. Cमेथड ओवरराइडिंगMethod overriding
  4. Dउपरोक्त सभीAll the above

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

हल / Solution
बहुरूपता का मतलब है एक नाम और कई रूप। मेथड ओवरलोडिंग और कंस्ट्रक्टर ओवरलोडिंग, दोनों में एक ही नाम की कई इकाइयाँ अलग-अलग पैरामीटर के साथ रहती हैं और चुनाव compiler करता है, इसलिए वे संकलन-समय बहुरूपता हैं। मेथड ओवरराइडिंग में चुनाव चलते समय object देखकर होता है, इसलिए वह रनटाइम बहुरूपता है। तीनों इसी अवधारणा के हिस्से हैं, इसलिए सही उत्तर उपरोक्त सभी है, किसी एक को चुनना अधूरा रहेगा।
Polymorphism means one name with many forms. Method overloading and constructor overloading both keep several units with the same name but different parameter lists, and the compiler makes the choice, so they are compile-time polymorphism. Method overriding decides the version while the program runs, by looking at the object, so it is runtime polymorphism. All three belong to the same idea, which is why the correct answer is all the above, and picking any single one would be incomplete.
प्रश्न 3उत्तर + हल

 

इस प्रोग्राम का आउटपुट है:  public class PolymorphismDemoClass2 {     void m1(String x){         System.out.println("One");     }     protected void m1(String x, String y){         System.out.println("Two");     }     public static void main(String[] args){         PolymorphismDemoClass2 obj = new PolymorphismDemoClass2();         obj.m1("ABC");         obj.m1("PQR", "XYZ");     } }
What is the output of this program?  public class PolymorphismDemoClass2 {     void m1(String x){         System.out.println("One");     }     protected void m1(String x, String y){         System.out.println("Two");     }     public static void main(String[] args){         PolymorphismDemoClass2 obj = new PolymorphismDemoClass2();         obj.m1("ABC");         obj.m1("PQR", "XYZ");     } }
  1. ATwo One
  2. BOne Two
  3. Cकम्पाइल टाइम एररCompile time error
  4. Dरनटाइम एररRuntime error

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

हल / Solution
यहाँ m1 नाम की दो method हैं — एक में एक String पैरामीटर है, दूसरी में दो। पैरामीटर की संख्या अलग है, इसलिए यह ठीक ओवरलोडिंग है। access modifier अलग होने से कोई फ़र्क़ नहीं पड़ता, ओवरलोडिंग में उसे गिना ही नहीं जाता, इसलिए कोई एरर नहीं आता। main में पहले obj.m1("ABC") चला, जिससे One छपा, फिर obj.m1("PQR", "XYZ") चला, जिससे Two छपा। इसलिए क्रम से आउटपुट One Two बनता है।
There are two methods named m1 here, one taking a single String parameter and the other taking two. The number of parameters differs, so this is proper overloading. The different access modifier makes no difference, because a modifier is not a part of the signature, and no error is raised. In main the call obj.m1("ABC") runs first and prints One, then obj.m1("PQR", "XYZ") runs and prints Two. So the output, in order, is One Two.
प्रश्न 4उत्तर + हल

 

इस प्रोग्राम का आउटपुट है:  public class PolymorphismDemoClass {     void add(int x, int y){         System.out.println("1. Addition is: " +(x+y));     }     void add(int y, int x){         System.out.println("2. Addition is: " +(x+y));     }     public static void main(String[] args){         PolymorphismDemoClass obj = new PolymorphismDemoClass();         obj.add(20, 30);     } }
What is the output of this program?  public class PolymorphismDemoClass {     void add(int x, int y){         System.out.println("1. Addition is: " +(x+y));     }     void add(int y, int x){         System.out.println("2. Addition is: " +(x+y));     }     public static void main(String[] args){         PolymorphismDemoClass obj = new PolymorphismDemoClass();         obj.add(20, 30);     } }
  1. A"2. Addition is: 50" छपेगाPrints 2. Addition is: 50
  2. B"1. Addition is: 50" छपेगाPrints 1. Addition is: 50
  3. Cकम्पाइल टाइम एररCompile time error
  4. Dरनटाइम एररRuntime error

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

हल / Solution
देखने में लगता है कि दोनों add अलग हैं, क्योंकि पैरामीटर के नाम उलट दिए गए हैं। पर ओवरलोडिंग में नाम नहीं गिने जाते, केवल पैरामीटर की संख्या, प्रकार और क्रम गिने जाते हैं। दोनों method का signature एक ही है — दो int। इसलिए compiler इसे दोहराई हुई method मानकर वहीं रोक देता है और कोई आउटपुट बनता ही नहीं। यानी उत्तर कम्पाइल टाइम एरर है। रनटाइम एरर तब आता जब प्रोग्राम कम से कम चलने लायक बन जाता।
The two add methods seem different, because the names of the parameters have been swapped. But overloading never counts parameter names; it counts only their number, their types and their order. Both methods here have the same signature, two int values, so the compiler treats the second one as a duplicate method and stops right there. No output is ever produced, so the answer is a compile time error. A runtime error would need the program to compile first.
प्रश्न 5उत्तर + हल

 

क्या हम जावा में main() विधि को ओवरलोड कर सकते हैं?
Can we overload the main() method in Java?
  1. Aनहीं, main() मेथड को ओवरलोड नहीं किया जा सकता।No, the main() method cannot be overloaded.
  2. Bहाँ, main() मेथड को ओवरलोड किया जा सकता है।Yes, the main() method can be overloaded.
  3. Cओवरलोडिंग के लिए केवल main() का return type बदला जा सकता है।Only the return type of the main() method can be changed for overloading.
  4. Dओवरलोडिंग जावा की मेथड पर लागू होने वाली अवधारणा नहीं है।Overloading is not a concept applicable to Java methods.

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

हल / Solution
main() भी आख़िर एक साधारण method ही है, इसलिए उसे ओवरलोड किया जा सकता है। एक ही class में अलग-अलग पैरामीटर वाली कई main लिखी जा सकती हैं। पर याद रखिए, प्रोग्राम शुरू करते समय JVM हमेशा वही main ढूँढ़ती है जिसका पैरामीटर String का array हो; बाक़ी रूपों को आपको उसी के भीतर से बुलाना पड़ेगा। तीसरा विकल्प ग़लत है क्योंकि केवल return type बदलने से ओवरलोडिंग होती ही नहीं, और चौथा विकल्प तो सीधे-सीधे ग़लत है।
The main() method is an ordinary method in the end, so it can be overloaded. A class may hold several versions of main with different parameter lists. Remember, though, that while starting the program the JVM always looks for the version whose parameter is an array of String; the other versions have to be called from inside it. The third option is wrong because changing only the return type never creates overloading, and the fourth option is plainly false.
प्रश्न 6उत्तर + हल

 

ओवरराइड की गई विधि में सुपरक्लास की विधि को कॉल करने के लिए किस कीवर्ड का उपयोग किया जाता है?
Which keyword is used to call the superclass method in the overridden method?
  1. Athis
  2. Bsuper
  3. Cextends
  4. Dinstanceof

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

हल / Solution
सबक्लass में method ओवरराइड करने के बाद भी कई बार सुपरक्लास वाला पुराना काम चाहिए होता है। तब super कीवर्ड लगाकर उसे बुलाते हैं, जैसे super.move(); इससे पुराना बरताव भी चलता है और नया भी जुड़ जाता है। this अपनी ही वस्तु की ओर इशारा करता है, इसलिए उससे वही ओवरराइड वाली method दोबारा चलेगी और अनंत चक्र बन सकता है। extends केवल घोषणा में वंशानुक्रम जोड़ता है और instanceof सिर्फ़ प्रकार जाँचता है।
Even after a subclass overrides a method, the work of the superclass version is often still needed. The super keyword calls it, as in super.move(), so the old behaviour runs first and the new behaviour is added on top. The keyword this points to the current object, so it would call the overriding method again and may build an endless loop. The keyword extends only sets up inheritance in the declaration, and instanceof merely checks the type of an object.
प्रश्न 7उत्तर + हल

 

बहुरूपता में, सुपरक्लास का एक संदर्भ चर (reference variable) किन वर्गों की वस्तु को संदर्भित कर सकता है?
In polymorphism, a reference variable of the superclass can refer to the object of which classes?
  1. Aकेवल सुपरक्लास कीOnly the superclass
  2. Bकेवल सबक्लास कीOnly the subclass
  3. Cकिसी भी क्लास कीAny class
  4. Dसुपरक्लास या उसकी किसी भी सबक्लास कीThe superclass or any of its subclasses

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

हल / Solution
जावा में ऊपर की ओर casting अपने आप हो जाती है, इसलिए सुपरक्लास का संदर्भ चर अपनी class का object भी रख सकता है और अपनी किसी भी सबक्लास का भी। यही बात रनटाइम बहुरूपता को संभव बनाती है। पहला और दूसरा विकल्प आधा सच कहते हैं, क्योंकि दोनों में से एक हालत छूट जाती है। तीसरा विकल्प ज़्यादा कह देता है — जिस class का इस पदानुक्रम से नाता नहीं, उसका object रखने पर compiler रोक देता है।
In Java an upcast happens automatically, so a superclass reference variable may hold an object of its own class as well as an object of any of its subclasses. This is exactly what makes runtime polymorphism possible. The first two options are only half true, since each of them leaves out one of these cases. The third option claims too much, because an object of a class outside this hierarchy is rejected by the compiler.
प्रश्न 8उत्तर + हल

 

किस परिदृश्य में जावा बहुरूपता (polymorphism) की अनुमति नहीं देता है?
In which scenario does Java NOT allow polymorphism?
  1. Aजब private मेथड को ओवरराइड किया जाएWhen overriding private methods
  2. Bजब मेथड ओवरलोडिंग का उपयोग होWhen using the method overloading
  3. Cजब interface की मेथड का उपयोग होWhen using interface methods
  4. Dजब abstract मेथड का उपयोग होWhen using abstract methods

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

हल / Solution
private मेथड केवल अपनी class के भीतर दिखती है, सबक्लास तक पहुँचती ही नहीं। इसलिए सबक्लास में वही नाम लिखने पर वह ओवरराइड नहीं होती, एक नई अलग मेथड बन जाती है और चुनाव compile time पर हो जाता है। यानी वहाँ रनटाइम बहुरूपता बनती ही नहीं। बाक़ी तीनों में बहुरूपता चलती है — ओवरलोडिंग संकलन-समय वाली देती है, और interface तथा abstract मेथड तो बनी ही इसलिए हैं कि उन्हें लागू करने वाली class अपने ढंग से काम करे।
A private method is visible only inside its own class and never reaches a subclass. So writing the same name in a subclass does not override it; a fresh separate method is created and the call is settled at compile time. Runtime polymorphism therefore cannot happen there. The other three cases do allow polymorphism, because overloading gives the compile-time kind, while interface methods and abstract methods exist exactly so that each implementing class can supply its own behaviour.
प्रश्न 9उत्तर + हल

 

इनमें से कौन संकलन-समय बहुरूपता (compile-time polymorphism) की अनुमति देता है?
Which of these allows compile-time polymorphism?
  1. Aमेथड ओवरलोडिंगMethod overloading
  2. Bमेथड ओवरराइडिंगMethod overriding
  3. CदोनोंBoth
  4. Dइनमें से कोई नहींNone of the above

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

हल / Solution
संकलन-समय बहुरूपता का मतलब है कि कौन सी method चलेगी यह compiler ही तय कर दे। ओवरलोडिंग में एक ही नाम की कई method होती हैं और call में दिए तर्कों की संख्या तथा प्रकार देखकर compiler सही method जोड़ देता है, इसलिए वही इसका उदाहरण है। ओवरराइडिंग में यह फ़ैसला चलते समय object के असली प्रकार से होता है, इसलिए वह रनटाइम बहुरूपता है। दूसरा विकल्प ग़लत है, इसलिए दोनों वाला विकल्प भी टिकता नहीं।
Compile-time polymorphism means that the compiler itself settles which method will run. In overloading there are several methods with one name, and the compiler joins the call to the right one by reading the number and the types of the arguments, so overloading is the example of it. In overriding the decision is taken while the program runs, so that is runtime polymorphism. Since the second option is wrong, both and none cannot stand.
प्रश्न 10उत्तर + हल

 

जावा में, कौन सी अवधारणा हमें रनटाइम बहुरूपता (runtime polymorphism) को लागू करने की अनुमति देती है?
In Java, which concept allows us to implement runtime polymorphism?
  1. Aमेथड ओवरलोडिंगMethod overloading
  2. Bमेथड ओवरराइडिंगMethod overriding
  3. Cकंस्ट्रक्टरConstructors
  4. Dस्टैटिक मेथडStatic methods

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

हल / Solution
रनटाइम बहुरूपता तब बनती है जब सबक्लास सुपरक्लास की method को उसी नाम और उसी signature के साथ दोबारा लिखे। यही मेथड ओवरराइडिंग है। सुपरक्लास के संदर्भ में सबक्लास का object रखने पर JVM चलते समय object देखकर सही method चुनती है। ओवरलोडिंग का फ़ैसला compiler पहले ही कर देता है, इसलिए वह compile time polymorphism है। कंस्ट्रक्टर वंशानुक्रम में उतरते नहीं, और स्टैटिक मेथड ओवरराइड नहीं होतीं, वे सिर्फ़ छिपती हैं।
Runtime polymorphism appears when a subclass writes a method of its superclass again with the same name and the same signature, which is method overriding. If a subclass object is kept in a superclass reference, the JVM looks at the object while the program runs and picks the right method. Overloading is settled by the compiler beforehand, so it is compile time polymorphism. Constructors are not inherited, and static methods are never overridden, they are only hidden.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 11उत्तर app में

 

कौन सा सिद्धांत विभिन्न वर्गों को वंशानुक्रम के माध्यम से एक ही वर्ग के उदाहरण (instance) के रूप में मानने की अनुमति देता है?
Which principle allows different classes to be treated as instances of the same class through inheritance?
  1. Aएनकैप्सुलेशनEncapsulation
  2. Bएब्स्ट्रैक्शनAbstraction
  3. CइनहेरिटेंसInheritance
  4. Dपॉलीमॉर्फिज़्मPolymorphism
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 13उत्तर app में

 

वंशानुक्रम (inheritance) को लागू करने में OOP की किस विशेषता का बड़े पैमाने पर उपयोग किया जाता है?
Which feature of OOP is extensively used in implementing inheritance?
  1. Aडायनामिक बाइंडिंगDynamic binding
  2. Bएब्स्ट्रैक्शनAbstraction
  3. Cऑपरेटर ओवरलोडिंगOperator overloading
  4. Dपॉलीमॉर्फिज़्मPolymorphism
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में

 

OOP के किस फीचर का व्यवहार ऑपरेशन में उपयोग किए गए डेटा के प्रकार पर निर्भर करता है?
Which feature of OOP has behaviour that depends upon the types of data used in the operation?
  1. AइनहेरिटेंसInheritance
  2. Bपॉलीमॉर्फिज़्मPolymorphism
  3. Cएब्स्ट्रैक्शनAbstraction
  4. Dएनकैप्सुलेशनEncapsulation
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 15उत्तर app में

 

ओवरराइडिंग फ़ंक्शन द्वारा OOP की कौन सी विशेषता प्रदर्शित की जाती है?
Which feature of OOP is exhibited by function overriding?
  1. Aपॉलीमॉर्फिज़्मPolymorphism
  2. Bएनकैप्सुलेशनEncapsulation
  3. Cएब्स्ट्रैक्शनAbstraction
  4. DइनहेरिटेंसInheritance
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 16उत्तर app में

 

निम्नलिखित में से कौन सा मेम्बर फ़ंक्शन ओवरराइडिंग का सबसे अच्छा वर्णन करता है?
Which of the following best describes member function overriding?
  1. Aऐसे मेम्बर फ़ंक्शन जिनका नाम केवल derived class में एक जैसा होMember functions having the same name in derived class only
  2. Bऐसे मेम्बर फ़ंक्शन जिनका नाम एक जैसा और signature अलग हो, main फ़ंक्शन के भीतरMember functions having the same name and different signature inside main function
  3. Cऐसे मेम्बर फ़ंक्शन जिनका नाम base और derived दोनों class में एक जैसा होMember functions having the same name in base and derived classes
  4. Dऐसे मेम्बर फ़ंक्शन जिनका नाम केवल base class में एक जैसा होMember functions having the same name in base class only
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में

 

निम्नलिखित में से किसका उपयोग पॉलीमॉरफिस्म की अवधारणा के लिए नहीं किया जा सकता है?
Which among the following cannot be used for the concept of polymorphism?
  1. Aस्टैटिक मेम्बर फंक्शनStatic member function
  2. Bकंस्ट्रक्टर ओवरलोडिंगConstructor Overloading
  3. Cमेम्बर फंक्शन ओवरलोडिंगMember function overloading
  4. Dग्लोबल मेम्बर फंक्शनGlobal member function
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में

 

पॉलीमॉरफिस्म के लिए निम्नलिखित में से कौन सी परिभाषा गलत है?
Which of the following definitions is incorrect for polymorphism?
  1. Aपॉलीमॉर्फिज़्म एक ही कार्यक्षमता को दोबारा परिभाषित करने में मदद करता हैPolymorphism helps in redefining the same functionality
  2. Bपॉलीमॉर्फिज़्म ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग (OOP) की एक विशेषता हैPolymorphism concept is the feature of object-oriented programming (OOP)
  3. Cयह फंक्शन परिभाषा का ओवरहेड हमेशा बढ़ाता हैIt always increases the overhead of function definition
  4. Dप्रोग्राम की पठनीयता में आसानी होती हैEase in the readability of the program
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में

 

जावा में मेथड ओवरलोडिंग क्या है?
What is method overloading in Java?
  1. Aकिसी मेथड को दूसरी मेथड से कॉल करना।Calling a method from another method.
  2. Bरनटाइम पर मेथड का नाम बदल देना।Renaming a method at runtime.
  3. Cएक ही क्लास में एक ही नाम की कई मेथड रखना पर उनके पैरामीटर अलग-अलग होना।Having multiple methods with the same name but different parameters in a class.
  4. Dसबक्लास में सुपरक्लास की मेथड को ओवरराइड करना।Overriding a superclass method in a subclass.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 20उत्तर app में

 

निम्नलिखित जावा कोड में, sum() विधि के लिए कौन सी कॉल उपयुक्त है? class Output  {           public static int sum(int ...x)         {              return 0;          }         static void main(String args[])          {                  sum(10);              sum(10,20);              sum(10,20,30);              sum(10,20,30,40);         }  }
In the following Java code, which call to the sum() method is appropriate? class Output  {           public static int sum(int ...x)         {              return 0;          }         static void main(String args[])          {                  sum(10);              sum(10,20);              sum(10,20,30);              sum(10,20,30,40);         }  }
  1. Aकेवल sum(10)only sum(10)
  2. Bकेवल sum(10,20)only sum(10,20)
  3. Cकेवल sum(10) और sum(10,20)only sum(10) & sum(10,20)
  4. Dउपरोक्त सभीall of the mentioned
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 21उत्तर app में

 

विधि हस्ताक्षर (method signature) से विभेदित एक ही वर्ग में एक से अधिक विधियों को परिभाषित करने की प्रक्रिया क्या है?
What is the process of defining more than one method in a class differentiated by method signature?
  1. Aफंक्शन ओवरराइडिंगFunction overriding
  2. Bफंक्शन ओवरलोडिंगFunction overloading
  3. Cफंक्शन डबलिंगFunction doubling
  4. Dइनमें से कोई नहींNone of the mentioned
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 22उत्तर app में

 

निम्नलिखित जावा प्रोग्राम का आउटपुट क्या है? class Parent {     String name = "parent";     String message() {         return "from parent";     } } class Child extends Parent {     String name = "child";     String message() {         return "from child";     } } public class Main {     public static void main(String[] args) {         Parent p = new Child();         System.out.println(p.name + " " + p.message());     } }
What is the output of the following Java program? class Parent {     String name = "parent";     String message() {         return "from parent";     } } class Child extends Parent {     String name = "child";     String message() {         return "from child";     } } public class Main {     public static void main(String[] args) {         Parent p = new Child();         System.out.println(p.name + " " + p.message());     } }
  1. A"parent from parent"
  2. B"child from child"
  3. C"parent from child"
  4. D"child from parent"
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 23उत्तर app में

 

निम्नलिखित जावा प्रोग्राम का आउटपुट क्या है? public class Vehicle {     public void move() {         System.out.println("The vehicle moves");     } } public class Car extends Vehicle {     public void move() {         System.out.println("The car moves");     } } public class Main {     public static void main(String[] args) {         Vehicle vehicle = new Car();         vehicle.move();     } }
What is the output of the following Java program? public class Vehicle {     public void move() {         System.out.println("The vehicle moves");     } } public class Car extends Vehicle {     public void move() {         System.out.println("The car moves");     } } public class Main {     public static void main(String[] args) {         Vehicle vehicle = new Car();         vehicle.move();     } }
  1. A"The vehicle moves"
  2. B"The car moves"
  3. Cकोड कम्पाइल नहीं होताThe code does not compile
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 24उत्तर app में

 

जावा में, क्या स्थैतिक (static) विधि को ओवरराइड करना संभव है?
In Java, is it possible to override a static method?
  1. Aहाँ, static मेथड को भी instance मेथड की तरह ओवरराइड किया जा सकता है।Yes, we can override a static method just like we do with instance methods.
  2. Bनहीं, static मेथड ओवरराइड नहीं हो सकती क्योंकि वे class की होती हैं, object की नहीं।No, static methods cannot be overridden because they belong to the class, not the object.
  3. Cयह इस बात पर निर्भर करता है कि static मेथड final घोषित है या नहीं।It depends on whether the static method is declared as final or not.
  4. Dयह static मेथड के access modifier पर निर्भर करता है।It depends on the access modifier of the static method.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 25उत्तर app में
निम्नलिखित जावा कोड का आउटपुट क्या होगा?

class overload

{

int x;

double y;

void add(int a, int b)

{

x = a + b;

}

void add(double c, double d)

{

y = c + d;

}

overload()

{

this.x = 0;

this.y = 0;

}

}

class Overload_methods

{

public static void main(String args[])

{

overload obj = new overload();

int a = 2;

double b = 3.2;

obj.add(a, a);

obj.add(b, b);

System.out.println(obj.x + " " + obj.y);

}

}
What will be the output of the following Java code?

class overload

{

int x;

double y;

void add(int a, int b)

{

x = a + b;

}

void add(double c, double d)

{

y = c + d;

}

overload()

{

this.x = 0;

this.y = 0;

}

}

class Overload_methods

{

public static void main(String args[])

{

overload obj = new overload();

int a = 2;

double b = 3.2;

obj.add(a, a);

obj.add(b, b);

System.out.println(obj.x + " " + obj.y);

}

}
  1. A6 6
  2. B6.4 6.4
  3. C6.4 6
  4. D4 6.4
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 26उत्तर app में
निम्नलिखित जावा कोड का आउटपुट क्या होगा?

class overload

{

int x;

int y;

void add(int a)

{

x = a + 1;

}

void add(int a, int b)

{

x = a + 2;

}

}

class Overload_methods

{

public static void main(String args[])

{

overload obj = new overload();

int a = 0;

obj.add(6);

System.out.println(obj.x);

}

}
What will be the output of the following Java code?

class overload

{

int x;

int y;

void add(int a)

{

x = a + 1;

}

void add(int a, int b)

{

x = a + 2;

}

}

class Overload_methods

{

public static void main(String args[])

{

overload obj = new overload();

int a = 0;

obj.add(6);

System.out.println(obj.x);

}

}
  1. A5
  2. B6
  3. C7
  4. D8
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 27उत्तर app में
निम्नलिखित जावा कोड का आउटपुट क्या होगा?

class San

{

public void m1 (int i,float f)

{

System.out.println(" int float method");

}

public void m1(float f,int i);

{

System.out.println("float int method");

}

public static void main(String[]args)

{

San s=new San();

s.m1(20,20);

}

}
What will be the output of the following Java code?

class San

{

public void m1 (int i,float f)

{

System.out.println(" int float method");

}

public void m1(float f,int i);

{

System.out.println("float int method");

}

public static void main(String[]args)

{

San s=new San();

s.m1(20,20);

}

}
  1. Aint float method
  2. Bfloat int method
  3. Cकम्पाइल टाइम एररcompile time error
  4. Dरन टाइम एररrun time error
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 29उत्तर app में
एक ही क्लास के भीतर दो या दो से अधिक मेथड्स को परिभाषित करने की प्रक्रिया क्या है जिनका एक ही नाम है लेकिन अलग-अलग पैरामीटर्स की घोषणा है?
What is the process of defining two or more methods within the same class that have the same name but different parameter declarations?
  1. Aमेथड ओवरलोडिंगmethod overloading
  2. Bमेथड ओवरराइडिंगmethod overriding
  3. Cमेथड हाइडिंगmethod hiding
  4. Dइनमें से कोई नहींnone of the mentioned
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 30उत्तर app में
ओवरलोडिंग कब नहीं होती है?
When does overloading not occur?
  1. Aएक ही नाम की कई मेथड, पर signature अलग और पैरामीटर की संख्या या प्रकार अलगMore than one method with same name but different method signature and different number or type of parameters
  2. Bएक ही नाम की कई मेथड, पर पैरामीटर की संख्या अलगMore than one method with same name but different number of parameters
  3. Cएक ही नाम की कई मेथड, पैरामीटर की संख्या समान पर प्रकार अलगMore than one method with same name, same number of parameters but different type of parameters
  4. Dएक ही नाम की कई मेथड, पैरामीटर की संख्या और प्रकार समान पर signature अलगMore than one method with same name, same number of parameters and type but different signature
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
OOPs Concepts - Polymorphism के सभी 35 प्रश्न — उत्तर, हल और अभ्यास

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

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

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

Programmer Java के दूसरे topics

सभी topics