पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
अलग-अलग ऑब्जेक्ट बनाने के लिए टेम्पलेट (साँचा) कौन-सा है?
Which one is a template for creating different objects?
Aऐरे (Array)An Array
Bक्लास (Class)A class
Cइंटरफ़ेस (Interface)Interface
Dमेथड (Method)Method
सही उत्तर / Answer: (B)
हल / Solution
class एक साँचे या नक़्शे की तरह है। इसमें लिखा रहता है कि object में कौन-से variables (data) और कौन-से methods (काम) होंगे। एक ही class से new लगाकर कई अलग-अलग object बनाए जा सकते हैं, हर एक का अपना data होता है। array सिर्फ़ एक जैसे मानों का समूह है। interface का object सीधे नहीं बनता, उसे कोई class implement करती है। method तो class के अंदर का एक काम है।
A class works like a template or blueprint. It states which variables (data) and which methods (behaviour) an object will have. Using new, many different objects can be created from one class, each with its own data. An array is only a group of values of the same type. An interface cannot be instantiated directly; a class has to implement it. A method is just one task inside a class.
प्रश्न 2उत्तर + हल
जावा में "this" कीवर्ड का कौन-सा उपयोग नहीं है?
What is not the use of the "this" keyword in Java?
Aलोकल वेरिएबल का नाम एक जैसा होने पर इंस्टेंस वेरिएबल को रेफ़र करनाReferring to the instance variable when a local variable has the same name
Bस्वयं को उसी क्लास के मेथड में पास करनाPassing itself to the method of the same class
Cस्वयं को किसी दूसरे मेथड में पास करनाPassing itself to another method
Dकंस्ट्रक्टर चेनिंग में दूसरे कंस्ट्रक्टर को कॉल करनाCalling another constructor in constructor chaining
सही उत्तर / Answer: (B)
हल / Solution
this मौजूदा object का reference है। इसके मुख्य उपयोग हैं: parameter और instance variable का नाम एक जैसा हो तो this.x से instance variable बताना, this() से उसी class का दूसरा constructor बुलाना, और this को argument बनाकर किसी दूसरे method या object को भेजना। उसी class के instance method के पास this पहले से होता है, इसलिए उसे this पास करने की ज़रूरत नहीं पड़ती। इसे this का उपयोग नहीं गिना जाता।
this is a reference to the current object. Its main uses are: using this.x to reach the instance variable when a parameter has the same name, using this() to call another constructor of the same class, and passing this as an argument to another method or object. An instance method of the same class already has this, so there is no need to pass it there. That is not counted as a use of this.
प्रश्न 3उत्तर + हल
निम्नलिखित में से कौन जावा में OOPS अवधारणा नहीं है?
Which of the following is not an OOPS concept in Java?
Aपॉलीमॉर्फ़िज़्म (Polymorphism)Polymorphism
Bइनहेरिटेंस (Inheritance)Inheritance
Cकंपाइलेशन (Compilation)Compilation
Dएनकैप्सुलेशन (Encapsulation)Encapsulation
सही उत्तर / Answer: (C)
हल / Solution
OOPS की चार मुख्य अवधारणाएँ हैं: encapsulation, inheritance, polymorphism और abstraction। ये सब बताती हैं कि classes और objects के साथ program कैसे बनाया जाए। compilation इनमें नहीं है। compilation तो source code को byte code या machine code में बदलने की प्रक्रिया है, जो हर भाषा में होती है, चाहे वह object-oriented हो या न हो। इसलिए उत्तर compilation है।
The four main OOPS concepts are encapsulation, inheritance, polymorphism and abstraction. They describe how to build a program with classes and objects. Compilation is not one of them. Compilation is the process of turning source code into byte code or machine code, and it happens in every language, whether object-oriented or not. So the answer is compilation, which is option 3.
encapsulation में class के data को private रखकर बाहर से छिपाया जाता है और उस तक पहुँच सिर्फ़ methods से दी जाती है। इसलिए इसे data hiding भी कहते हैं। data hiring कोई शब्द नहीं, यह hiding से मिलता-जुलता भ्रम वाला विकल्प है। data abstraction अलग अवधारणा है। उसमें ज़रूरी बातें दिखाई जाती हैं और भीतर का ढंग छिपाया जाता है, जैसे abstract class और interface से।
In encapsulation, the data of a class is kept private and hidden from outside, and access is given only through methods. That is why it is also called data hiding. Data hiring is not a real term; it is a look-alike distractor. Data abstraction is a different concept. It shows only the essential features and hides how things work inside, as done with abstract classes and interfaces.
प्रश्न 5उत्तर + हल
एनकैप्सुलेशन कैसे प्राप्त किया जा सकता है?
How can encapsulation be achieved?
Aएक्सेस स्पेसिफ़ायर का उपयोग करकेUsing access specifiers
Bइनहेरिटेंस का उपयोग करकेUsing inheritance
Cकेवल private सदस्यों का उपयोग करकेUsing only private members
Dकोई नहींNone
सही उत्तर / Answer: (A)
हल / Solution
encapsulation में data को छिपाकर उस तक पहुँच नियंत्रित की जाती है। यह access specifiers से होता है: variables को private रखा जाता है और getter-setter जैसे methods को public। यानी private और public दोनों का मिला-जुला उपयोग चाहिए। सिर्फ़ private सदस्य रखें तो data तक कोई पहुँच ही नहीं बचेगी, इसलिए विकल्प 3 अधूरा है। inheritance गुण लेने की अवधारणा है, data छिपाने की नहीं।
Encapsulation hides data and controls access to it. This is done with access specifiers: variables are kept private and methods such as getters and setters are made public. So both private and public are used together. With only private members, there would be no way to reach the data at all, so option 3 is incomplete. Inheritance is about taking features from a class, not about hiding data.
प्रश्न 6उत्तर + हल
जावा में एनकैप्सुलेशन प्राप्त करने के कितने तरीक़े हैं?
How many ways are there to achieve encapsulation in Java?
A3
B2
C4
Dकोई नहींNone
सही उत्तर / Answer: (B)
हल / Solution
Java में encapsulation दो क़दमों से मिलता है। पहला, class के variables को private बनाइए, ताकि बाहर की class उन्हें सीधे न छू सके। दूसरा, उन variables को पढ़ने और बदलने के लिए public getter और setter methods दीजिए। इस तरह data छिपा रहता है और उस तक पहुँच सिर्फ़ नियंत्रित methods से होती है। इसलिए encapsulation पाने के दो तरीक़े माने जाते हैं और उत्तर 2 है।
In Java, encapsulation is achieved in two steps. First, make the variables of the class private, so outside classes cannot touch them directly. Second, provide public getter and setter methods to read and change those variables. This way the data stays hidden and can be reached only through controlled methods. So encapsulation is said to be achieved in two ways, and the answer is 2.
प्रश्न 7उत्तर + हल
हम रैपर क्लास (wrapper class) का उपयोग क्यों करते हैं?
Why do we use a wrapper class?
Aप्रिमिटिव डेटा टाइप को ऑब्जेक्ट में बदलने के लिएTo convert primitive data types into objects
Bनॉन-प्रिमिटिव डेटा टाइप को ऑब्जेक्ट में बदलने के लिएTo convert non-primitive data types into objects
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (A)
हल / Solution
int, char, double जैसे primitive types object नहीं होते। पर collections जैसे ArrayList में सिर्फ़ object रखे जा सकते हैं। इसलिए हर primitive के लिए एक wrapper class है, जैसे int के लिए Integer और char के लिए Character। ये primitive मान को object में लपेट देती हैं। non-primitive types, जैसे String या array, पहले से ही object हैं, उन्हें बदलने की ज़रूरत नहीं। इसलिए विकल्प 2 और 3 ग़लत हैं।
Primitive types like int, char and double are not objects. But collections such as ArrayList can hold only objects. So there is a wrapper class for each primitive, such as Integer for int and Character for char. These wrap a primitive value inside an object. Non-primitive types like String or arrays are already objects, so they need no conversion. That is why options 2 and 3 are wrong.
प्रश्न 8उत्तर + हल
जावा में एकाधिक (multiple) वंशानुक्रम प्राप्त करने के लिए किस अवधारणा का उपयोग किया जाता है?
Which concept is used to achieve multiple inheritance in Java?
AIS-A संबंधIS-A Relationship
BInteract
Cइंटरफ़ेस (Interface)Interface
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (C)
हल / Solution
Java में एक class सिर्फ़ एक ही class को extends कर सकती है, ताकि दो parent में एक ही नाम के method होने पर उलझन न हो। पर एक class कई interfaces को implement कर सकती है, जैसे class A implements X, Y। इसी तरह Java में multiple inheritance मिलता है। IS-A संबंध तो हर inheritance में बनता है, वह multiple का साधन नहीं है। Interact नाम की कोई अवधारणा Java में नहीं है।
In Java a class can extend only one class, which avoids confusion when two parents have methods with the same name. But a class can implement many interfaces, such as class A implements X, Y. This is how Java achieves multiple inheritance. The IS-A relationship is formed in every inheritance, so it is not the tool for multiple inheritance. There is no concept called Interact in Java.
प्रश्न 9उत्तर + हल
हम जावा में वंशानुक्रम (Inheritance) का उपयोग क्यों करते हैं?
Why do we use inheritance in Java?
Aमेथड ओवरराइडिंग के लिएFor method overriding
Bकोड के पुनः उपयोग (Code Reusability) के लिएFor code reusability
CA और B दोनोंBoth A & B
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (C)
हल / Solution
inheritance के दो बड़े फ़ायदे हैं। पहला, code का दोबारा उपयोग: parent class में लिखा code child class को अपने आप मिल जाता है, उसे फिर से लिखना नहीं पड़ता। दूसरा, method overriding: child class parent के method को अपने ढंग से दोबारा लिख सकती है, जिससे runtime polymorphism मिलता है। overriding बिना inheritance के हो ही नहीं सकती। इसलिए दोनों कारण सही हैं और उत्तर 'A और B दोनों' है।
Inheritance has two main benefits. First, code reusability: code written in the parent class is available to the child class without writing it again. Second, method overriding: the child class can rewrite a parent method in its own way, which gives runtime polymorphism. Overriding is not possible without inheritance. So both reasons are right, and the answer is 'Both A & B'.
प्रश्न 10उत्तर + हल
वंशानुक्रम (Inheritance) की अवधारणा का प्रयोग किस भाषा में नहीं किया जाता है?
The concept of inheritance is not used in which language?
AC++
BJava
CPython
DC भाषाC Language
सही उत्तर / Answer: (D)
हल / Solution
inheritance एक OOP अवधारणा है, जिसमें एक class दूसरी class के गुण लेती है। इसके लिए भाषा में class होनी चाहिए। C++, Java और Python तीनों object-oriented भाषाएँ हैं और तीनों में inheritance होता है। C भाषा procedural है। उसमें class नहीं होती, सिर्फ़ structure और functions होते हैं। इसलिए C में inheritance की अवधारणा नहीं है और उत्तर C भाषा है।
Inheritance is an OOP concept in which one class takes the features of another class. For this, a language must have classes. C++, Java and Python are all object-oriented languages, and all three support inheritance. The C language is procedural. It has no classes, only structures and functions. So the concept of inheritance is not used in C, and the answer is option 4.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
कंस्ट्रक्टर से संबंधित कथन: (I) हर क्लास में कम से कम एक कंस्ट्रक्टर होना चाहिए। (II) यदि यूज़र ने कंस्ट्रक्टर नहीं बनाया है तो क्लास में डिफ़ॉल्ट कंस्ट्रक्टर का उपयोग होता है।
Statements related to constructor: (I) A class must have at least one constructor. (II) If the constructor is not made by the user, then the default constructor is used in the class.
Aकथन I ग़लत हैStatement I is wrong
Bकथन II ग़लत हैStatement II is wrong
Cकथन I और II दोनों सही हैंBoth statements I & II are right