पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 10 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
क्या constructor exception फेंक सकता है?
Can a constructor throw an exception?
Aनहीं, कभी नहींNo, never
Bनहीं, सिर्फ़ private हो तोNo, only if it is private
Cनहीं, सिर्फ़ default हो तोNo, only if it is default
Dहाँ, फेंक सकता हैYes, it can
सही उत्तर / Answer: (D)
हल / Solution
हाँ। किताब के «constructor के बारे में क्या सत्य है» वाले प्रश्न में «constructor exception नहीं फेंक सकता» को ग़लत विकल्प के रूप में रखा गया है, यानी वह फेंक सकता है। जो बातें सचमुच वर्जित हैं वे अलग हैं — return type लिखना, return statement रखना, और final, static, abstract या synchronized जैसा non-access modifier लगाना।
Yes. In the book's question on what is true about a constructor, 'a constructor cannot throw an exception' is placed as the wrong option, meaning it can throw one. The things genuinely forbidden are different — writing a return type, keeping a return statement, and applying a non-access modifier such as final, static, abstract or synchronized.
प्रश्न 2उत्तर + हल
private constructor का एक व्यावहारिक उपयोग क्या है, पाठ के अनुसार?
According to the text, what is one practical use of a private constructor?
Aclass को तेज़ चलानाMaking the class run faster
Binheritance बढ़ानाIncreasing inheritance
Cपैरामीटर की संख्या घटानाReducing the number of parameters
Dडेवलपर को object बनाने से रोकनाStopping a developer from creating objects
सही उत्तर / Answer: (D)
हल / Solution
पाठ कहता है — constructor पर private access modifier लगाने से object केवल उसी class के भीतर बन सकता है, कोई बाहरी class उसका object नहीं बना सकती, और «इसके इस्तेमाल से हम डेवलपर को object बनाने से रोक सकते हैं»। Singleton design pattern इसी concept पर टिका है, जहाँ एक ही instance रखना होता है।
The text says — applying the private access modifier to a constructor means the object can be created only inside that class, no outside class can create its object, and 'by using this we can stop a developer from creating objects'. The Singleton design pattern rests on this very concept, where only one instance is to be kept.
प्रश्न 3उत्तर + हल
बिना पैरामीटर वाले constructor को और किन नामों से जाना जाता है?
By what other names is a constructor without parameters known?
Czero parameter constructor या constructor without parameterZero parameter constructor or constructor without parameter
Dstatic constructorStatic constructor
सही उत्तर / Answer: (C)
हल / Solution
पाठ के शब्दों में — जो constructor पैरामीटर के बिना declare किया जाता है, उसे zero parameter constructor या constructor without parameter कहा जाता है, और वही Non-Parameterized Constructor है जो Java तथा C++ दोनों में होता है। copy constructor C++ का है, और static constructor नाम की कोई चीज़ Java में नहीं, क्योंकि constructor पर static लगता ही नहीं।
In the text's words — a constructor declared without parameters is called a zero parameter constructor or a constructor without parameter, and that is the Non-Parameterized Constructor. The copy constructor belongs to C++, and there is no such thing as a static constructor in Java, since static cannot be applied to a constructor at all.
प्रश्न 4उत्तर + हल
constructor की सही वाक्य-रचना कौन है?
Which is the correct syntax of a constructor?
Avoid Class_Name(Parameter_List) { Body }
BClass_Name Constructor(Parameter_List) { Body }
CClass_Name(Parameter_List) { Constructor_Body }
Dconstructor Class_Name(Parameter_List) { Body }
सही उत्तर / Answer: (C)
हल / Solution
पाठ में दी गई वाक्य-रचना यही है — Class_Name(Parameter_List) { Constructor_Body }। उससे पहले कोई return type नहीं आता, सो void वाला रूप ग़लत है; constructor नाम का कोई keyword Java में नहीं होता; और नाम के बाद अलग से Constructor लिखने की ज़रूरत नहीं, क्योंकि class के नाम से मेल खाना ही वह पहचान है जिससे compiler उसे constructor मानता है।
The syntax given in the text is just this — Class_Name(Parameter_List) { Constructor_Body }. No return type comes before it, so the form with void is wrong; there is no keyword called constructor in Java at all; and there is no need to write Constructor separately after the name, because matching the class name is itself the mark by which the compiler treats it as a constructor.
प्रश्न 5उत्तर + हल
constructor पर कोई access modifier न लिखा जाए तो उसकी पहुँच किस प्रकार की होती है?
If no access modifier is written on a constructor, what kind of access does it have?
Aprivate
Bpublic
Cprotected
Ddefault — यानी package-privatedefault — that is, package-private
सही उत्तर / Answer: (D)
हल / Solution
कुछ न लिखने पर constructor को default access मिलती है, जिसे package-private कहा जाता है — उसका object उसी package के भीतर से बन सकता है, बाहर के package से नहीं। छपे अध्याय की «By default constructor public टाइप का होता है» वाली पंक्ति इस बिंदु पर ग़लत है। उसी के साथ जो बात सही है वह यह कि चारों access modifier लग सकते हैं, पर कोई non-access modifier नहीं।
When nothing is written, a constructor gets default access, which is called package-private — its object can be created from within the same package but not from a package outside it. The printed chapter's line saying a constructor is of the public type by default is wrong on this point. What is correct alongside it is that all four access modifiers may be applied, but no non-access modifier.
प्रश्न 6उत्तर + हल
constructor आमतौर पर class का क्या होता है?
What is a constructor usually, in relation to a class?
Aएक static blockA static block
Bएक member functionA member function
Cएक अलग classA separate class
Dएक interfaceAn interface
सही उत्तर / Answer: (B)
हल / Solution
पाठ की दूसरी पंक्ति यही कहती है — «एक कंस्ट्रक्टर आमतौर पर एक class का member function होता है»। वह class के भीतर ही लिखा जाता है, उसका नाम class के नाम के समान होता है, और object बनते समय अपने आप चलता है। static block अलग चीज़ है और interface में constructor होता ही नहीं।
The text's second line says exactly this — 'a constructor is usually a member function of a class'. It is written inside the class itself, its name is the same as the class name, and it runs by itself as the object is created. A static block is a different thing, and an interface has no constructor at all.
प्रश्न 7उत्तर + हल
जिस class में एक भी constructor न लिखा जाए, उसका क्या होता है?
What happens to a class in which no constructor is written at all?
Acompiler ख़ुद एक default constructor जोड़ देता हैThe compiler itself adds a default constructor
Bउस class का object नहीं बन सकताNo object of that class can be created
Ccompile करते समय error मिलती हैAn error occurs while compiling
Dउसे abstract class मान लिया जाता हैIt is taken to be an abstract class
सही उत्तर / Answer: (A)
हल / Solution
छपा अध्याय कहता है कि सभी class में डिफ़ॉल्ट रूप से constructor होते हैं — कोई न लिखने पर compiler आपके लिए एक बना देता है, जिसे default constructor कहा जाता है, और वह numeric को 0, String को null तथा boolean को false कर देता है। यह जोड़ना compile के समय होता है और constructor सीधे .class file में लिख दिया जाता है; अध्याय की «रन टाइम के दौरान» वाली पंक्ति इस बिंदु पर ढीली है।
The printed chapter says all classes have constructors by default — if none is written, the compiler makes one for you, which is called the default constructor, and it sets numerics to 0, Strings to null and booleans to false. This addition happens at compile time and the constructor is written straight into the .class file; the chapter's phrase about run time is loose on this point.
प्रश्न 8उत्तर + हल
Java में constructor के भीतर return के बारे में क्या सही है?
In Java, what is correct about return inside a constructor?
Aबिना मान वाला «return;» चल जाता है, पर मान के साथ return नहींA bare 'return;' works, but return with a value does not
Bकिसी भी रूप में return लिखना वर्जित हैWriting return in any form is forbidden
Creturn के साथ उसी class का object देना अनिवार्य हैIt is compulsory to return an object of that class
Dसिर्फ़ «return void;» लिखा जा सकता हैOnly 'return void;' may be written
सही उत्तर / Answer: (A)
हल / Solution
constructor कोई मान नहीं लौटाता, इसलिए «return 5;» जैसा कुछ लिखने पर compile-time error मिलती है। पर बिना मान वाला «return;» उसमें वैध है और वहीं से लौटा देता है — यह Java की संहिता (JLS 8.8.7) का नियम है। छपे अध्याय की «return statement की अनुमति नहीं है» वाली पंक्ति असल में मान लौटाने वाले return की बात कह रही है; बिना मान वाला रूप उस रोक से बाहर है।
A constructor returns no value, so writing something like 'return 5;' gives a compile-time error. But a bare 'return;' is valid inside it and simply returns from that point — this is the rule of the Java language specification (JLS 8.8.7). The printed chapter's line that a return statement is not permitted actually speaks of a value-returning return; the bare form falls outside that restriction.
प्रश्न 9उत्तर + हल
Singleton design pattern किस concept पर टिका है?
Which concept does the Singleton design pattern rest on?
Acopy constructorCopy constructor
Bconstructor overloadingConstructor overloading
Cdefault constructorDefault constructor
Dprivate constructorPrivate constructor
सही उत्तर / Answer: (D)
हल / Solution
पाठ साफ़ लिखता है — सिंगलटन डिज़ाइन पैटर्न private constructor concept का उपयोग करता है। constructor private होने से object उसी class के भीतर ही बन सकता है, जिससे बाहर से जितने चाहें object बनाना रुक जाता है और «एक ही instance» वाली शर्त सध जाती है। copy constructor तो Java में ही नहीं, और overloading का इससे कोई लेना-देना नहीं।
The text states it plainly — the Singleton design pattern uses the private constructor concept. With a private constructor an object can be created only inside that class, which stops any number of objects being made from outside and secures the 'only one instance' condition. A copy constructor does not exist in Java at all, and overloading has nothing to do with this.
प्रश्न 10उत्तर + हल
Java और C++ में constructor के प्रकारों की संख्या क्रमशः क्या है?
What is the number of constructor types in Java and in C++ respectively?
Aतीन और दोThree and two
Bदो और दोTwo and two
Cदो और तीनTwo and three
Dतीन और तीनThree and three
सही उत्तर / Answer: (C)
हल / Solution
पाठ के शब्दों में — constructor Java में दो प्रकार के होते हैं पर C++ में तीन। Non-Parameterized और Parameterized दोनों भाषाओं में हैं, और तीसरा Copy Constructor पाठ में «C++ Only» लिखा है, इसीलिए Java की गिनती दो रह जाती है। C++ का copy constructor उसी class के object का reference लेकर नए object के सदस्य भरता है।
In the text's words — constructors are of two kinds in Java but three in C++. Non-Parameterized and Parameterized exist in both languages, and the third, the Copy Constructor, is marked 'C++ Only' in the text, which is why Java's count stays at two. C++'s copy constructor takes a reference to an object of the same class and fills the new object's members from it.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति