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

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

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

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

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

भाषा
प्रश्न 1उत्तर + हल
क्या constructor exception फेंक सकता है?
Can a constructor throw an exception?
  1. Aनहीं, कभी नहींNo, never
  2. Bनहीं, सिर्फ़ private हो तोNo, only if it is private
  3. Cनहीं, सिर्फ़ default हो तोNo, only if it is default
  4. 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?
  1. Aclass को तेज़ चलानाMaking the class run faster
  2. Binheritance बढ़ानाIncreasing inheritance
  3. Cपैरामीटर की संख्या घटानाReducing the number of parameters
  4. 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?
  1. Asingle parameter constructorSingle parameter constructor
  2. Bcopy constructorCopy constructor
  3. Czero parameter constructor या constructor without parameterZero parameter constructor or constructor without parameter
  4. 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?
  1. Avoid Class_Name(Parameter_List) { Body }
  2. BClass_Name Constructor(Parameter_List) { Body }
  3. CClass_Name(Parameter_List) { Constructor_Body }
  4. 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?
  1. Aprivate
  2. Bpublic
  3. Cprotected
  4. 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?
  1. Aएक static blockA static block
  2. Bएक member functionA member function
  3. Cएक अलग classA separate class
  4. 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?
  1. Acompiler ख़ुद एक default constructor जोड़ देता हैThe compiler itself adds a default constructor
  2. Bउस class का object नहीं बन सकताNo object of that class can be created
  3. Ccompile करते समय error मिलती हैAn error occurs while compiling
  4. 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?
  1. Aबिना मान वाला «return;» चल जाता है, पर मान के साथ return नहींA bare 'return;' works, but return with a value does not
  2. Bकिसी भी रूप में return लिखना वर्जित हैWriting return in any form is forbidden
  3. Creturn के साथ उसी class का object देना अनिवार्य हैIt is compulsory to return an object of that class
  4. 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?
  1. Acopy constructorCopy constructor
  2. Bconstructor overloadingConstructor overloading
  3. Cdefault constructorDefault constructor
  4. 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?
  1. Aतीन और दोThree and two
  2. Bदो और दोTwo and two
  3. Cदो और तीनTwo and three
  4. 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 — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 12उत्तर app में
एक class में कितने constructor हो सकते हैं?
How many constructors can one class have?
  1. Aशून्य, एक या एक से अधिकZero, one or more than one
  2. Bअधिकतम दोAt most two
  3. Cठीक एकExactly one
  4. Dकम से कम एक लिखना अनिवार्य हैWriting at least one is compulsory
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
default constructor numeric variable, String और boolean को किन मानों से भरता है?
What values does a default constructor initialise numeric variables, Strings and booleans with?
  1. A1, "" और true1, "" and true
  2. B0, null और false0, null and false
  3. C0, "0" और true0, "0" and true
  4. Dसबको nullnull for all
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में
क्या कंस्ट्रक्टर पर access modifier लग सकता है?
Can a constructor have access modifiers?
  1. Aहाँ, सिर्फ़ publicYes, only public
  2. Bहाँ, सिर्फ़ privateYes, only private
  3. Cहाँ — public, protected, private या package-privateYes, public, protected, private, or package-private
  4. Dनहीं, constructor पर access modifier नहीं लगताNo, constructors cannot have access modifiers
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
क्या जावा में कंस्ट्रक्टर के लिए access modifier का उपयोग किया जा सकता है?
Can we use access modifiers for constructors in Java?
  1. AहाँYes
  2. BनहींNo
  3. Cकुछ नहीं कहा जा सकताNothing can be said
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
अगर कन्स्ट्रक्टर के आगे रिटर्न टाइप लिख दिया जाए तो व्यवहार क्या होगा?
What would be the behaviour if a constructor is given a return type?
  1. Aकम्पाइलेशन त्रुटिCompilation error
  2. Bरनटाइम त्रुटिRuntime error
  3. Cकम्पाइल होकर सफलतापूर्वक चलेगाCompiles and runs successfully
  4. Dकेवल String रिटर्न टाइप की अनुमति हैOnly String return type is allowed
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 20उत्तर app में
निम्नलिखित C++ प्रोग्राम का आउटपुट क्या होगा?

#include

using namespace std;

class A

{

int i;

public:

A()

{

cout<<"Default Constructor ";

}

A(int x)

{

cout<<"Single Parameterized Constructor ";

}

A(int y, int x)

{

cout<<"Double Parameterized Constructor ";

}

};

int main()

{

A obj1(10);

A obj3;

return 0;

}
What will be the output of the following C++ program?

#include

using namespace std;

class A

{

int i;

public:

A()

{

cout<<"Default Constructor ";

}

A(int x)

{

cout<<"Single Parameterized Constructor ";

}

A(int y, int x)

{

cout<<"Double Parameterized Constructor ";

}

};

int main()

{

A obj1(10);

A obj3;

return 0;

}
  1. ASingle Parameterized Constructor Double Parameterized Constructor Default Constructor
  2. BSingle Parameterized Constructor Default Constructor
  3. CDouble Parameterized Constructor Default Constructor
  4. Dकंपाइल टाइम एररCompile Time Error
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
OOPs Concepts - Constructors के सभी 20 प्रश्न — उत्तर, हल और अभ्यास

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

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

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

Java के दूसरे topics

सभी topics