पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 16 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
String को Float object में बदलने के लिए किस method का उपयोग होता है?
Which method is used to convert a string to a Float object?
AvalueOf()
Bparse()
CtoFloat()
DconvertToFloat()
सही उत्तर / Answer: (A)
हल / Solution
Float.valueOf("1.5") String को पढ़कर Float object लौटाता है। यही wrapper classes का सामान्य नियम है, यानी valueOf() हमेशा object देता है। अगर primitive float चाहिए तो Float.parseFloat() लगता है। parse() नाम का अकेला method Float class में नहीं है। toFloat() और convertToFloat() भी Java में मौजूद नहीं हैं। इसलिए Float object पाने का सही उत्तर valueOf() है।
Float.valueOf("1.5") reads a String and returns a Float object. This is the general rule for wrapper classes: valueOf() always gives back an object. If you need a primitive float instead, you use Float.parseFloat(). There is no plain parse() method in the Float class. toFloat() and convertToFloat() do not exist in Java either. So the correct answer is valueOf(), which returns a Float object.
प्रश्न 2उत्तर + हल
Boolean class में booleanValue() method क्या करता है?
What does the booleanValue() method in the Boolean class do?
Aboolean primitive डेटा टाइप को उसके string रूप में बदलता हैConverts a boolean primitive data type to its string representation
BString को boolean primitive डेटा टाइप में बदलता हैConverts a string to a boolean primitive data type
Cइस Boolean object में रखा boolean मान लौटाता हैReturns the boolean value represented by this Boolean object
Dदो boolean objects की संख्यात्मक तुलना करता हैCompares two boolean objects numerically
सही उत्तर / Answer: (C)
हल / Solution
booleanValue() एक instance method है, जो Boolean object के भीतर रखा primitive true या false लौटाता है। जैसे Boolean.TRUE.booleanValue() का नतीजा true है। auto-unboxing में compiler यही method लगाता है। String रूप toString() देता है, और String से boolean बनाने के लिए parseBoolean() है। boolean मान संख्या नहीं होते, इसलिए संख्यात्मक तुलना वाला विकल्प भी ग़लत है।
booleanValue() is an instance method that returns the primitive true or false stored inside a Boolean object. For example, Boolean.TRUE.booleanValue() returns true. The compiler uses this method during auto-unboxing. The string form comes from toString(), and parseBoolean() turns a String into a boolean. Boolean values are not numbers, so the numeric comparison option is wrong too. Option 3 is correct.
प्रश्न 3उत्तर + हल
Double class में doubleValue() method क्या करता है?
What does the doubleValue() method in the Double class do?
Adouble primitive डेटा टाइप को उसके string रूप में बदलता हैConverts a double primitive data type to its string representation
BString को double primitive डेटा टाइप में बदलता हैConverts a string to a double primitive data type
Cइस Double object में रखा double मान लौटाता हैReturns the double value represented by this Double object
Dदो double objects की संख्यात्मक तुलना करता हैCompares two double objects numerically
सही उत्तर / Answer: (C)
हल / Solution
doubleValue() एक instance method है, जो Double object के भीतर रखा primitive double मान लौटाता है। जैसे Double.valueOf(2.5).doubleValue() का नतीजा 2.5 है। auto-unboxing में compiler यही method लगाता है। double से String बनाने का काम toString() करता है। String से double बनाने के लिए parseDouble() है। तुलना compareTo() करता है। इसलिए doubleValue() का सही वर्णन विकल्प 3 में है।
doubleValue() is an instance method that returns the primitive double stored inside a Double object. For example, Double.valueOf(2.5).doubleValue() returns 2.5. The compiler uses this method during auto-unboxing. Converting a double to a String is done by toString(). Converting a String to a double is the job of parseDouble(). Comparison is done by compareTo(). So option 3 correctly describes doubleValue().
प्रश्न 4उत्तर + हल
String को उसकी संगत wrapper class के object में बदलने के लिए किस method का उपयोग होता है?
Which method is used to convert a string to its corresponding wrapper class object?
AvalueOf()
Bparse()
Cconvert()
DtoString()
सही उत्तर / Answer: (A)
हल / Solution
wrapper classes का static valueOf(String) method String को पढ़कर wrapper object लौटाता है। जैसे Integer.valueOf("12") एक Integer object देता है। parseXxx() methods primitive लौटाते हैं, पर parse() नाम का अकेला method wrapper classes में नहीं है। convert() भी मौजूद नहीं है। toString() उलटा काम करता है, यानी object को String बनाता है। इसलिए सही उत्तर valueOf() है।
The static valueOf(String) method of the wrapper classes reads a String and returns a wrapper object. For example, Integer.valueOf("12") returns an Integer object. The parseXxx() methods return primitives, and there is no plain parse() method in the wrapper classes. convert() does not exist either. toString() does the reverse job, turning an object into a String. So the correct answer is valueOf().
प्रश्न 5उत्तर + हल
Integer class में parseInt() method क्या करता है?
What does the parseInt() method in the Integer class do?
AString को int primitive डेटा टाइप में बदलता हैConverts a string to an integer primitive data type
Bint primitive डेटा टाइप को उसके string रूप में बदलता हैConverts an integer primitive data type to its string representation
Cदो Integer objects की संख्यात्मक तुलना करता हैCompares two integer objects numerically
DInteger object का hash code लौटाता हैRetrieves the hash code of an integer object
सही उत्तर / Answer: (A)
हल / Solution
Integer.parseInt() एक static method है, जो String को पढ़कर primitive int लौटाता है। जैसे Integer.parseInt("42") का नतीजा 42 है। String में ग़लत अक्षर हों तो NumberFormatException आता है। int को String बनाने का काम Integer.toString() या String.valueOf() करता है। तुलना compare() या compareTo() से होती है, और hash code hashCode() देता है। इसलिए विकल्प 1 सही है।
Integer.parseInt() is a static method that reads a String and returns a primitive int. For example, Integer.parseInt("42") returns 42. If the String contains invalid characters, it throws a NumberFormatException. Turning an int into a String is done by Integer.toString() or String.valueOf(). Comparison is done with compare() or compareTo(), and hashCode() gives the hash code. So option 1 is correct.
प्रश्न 6उत्तर + हल
wrapper class object को उसके संगत primitive डेटा टाइप में बदलने के लिए किस method का उपयोग होता है?
Which method is used to convert a wrapper class object to its corresponding primitive data type?
AtoPrimitive()
BconvertToPrimitive()
CgetValue()
Dइनमें से कोई नहींNone of the above
सही उत्तर / Answer: (D)
हल / Solution
wrapper object से primitive निकालने के लिए xxxValue() methods होते हैं। जैसे intValue(), doubleValue(), booleanValue() और charValue()। यही काम auto-unboxing में compiler अपने आप करता है। toPrimitive(), convertToPrimitive() और getValue() नाम के methods wrapper classes में होते ही नहीं। दिए गए तीनों नाम ग़लत हैं, इसलिए सही उत्तर 'इनमें से कोई नहीं' है, क्योंकि असली method सूची में है ही नहीं।
Wrapper objects are converted to primitives with the xxxValue() methods, such as intValue(), doubleValue(), booleanValue() and charValue(). The compiler calls these same methods automatically during auto-unboxing. Methods named toPrimitive(), convertToPrimitive() and getValue() do not exist in the wrapper classes. Since none of the three listed names is a real method, the correct answer is None of the above.
प्रश्न 7उत्तर + हल
wrapper classes में compareTo() method क्या करता है?
What does the compareTo() method in wrapper classes do?
Aदो wrapper class objects की संख्यात्मक तुलना करता हैCompares two wrapper class objects numerically
Bwrapper class object को उसके संगत primitive डेटा टाइप में बदलता हैConverts a wrapper class object to its corresponding primitive data type
Cwrapper class object का string रूप लौटाता हैReturns the string representation of a wrapper class object
Dwrapper class object का hash code लौटाता हैRetrieves the hash code of a wrapper class object
सही उत्तर / Answer: (A)
हल / Solution
wrapper classes Comparable interface को लागू करती हैं, इसलिए उनमें compareTo() होता है। यह दो objects के मान की तुलना करता है। पहला छोटा हो तो ऋणात्मक, बराबर हो तो 0 और बड़ा हो तो धनात्मक मान देता है। जैसे Integer.valueOf(5).compareTo(8) ऋणात्मक देता है। primitive निकालना xxxValue(), string रूप toString() और hash code hashCode() का काम है।
Wrapper classes implement the Comparable interface, so they provide compareTo(). It compares the values of two objects. It returns a negative value if the first is smaller, 0 if both are equal, and a positive value if the first is larger. For example, Integer.valueOf(5).compareTo(8) is negative. Extracting a primitive is the job of xxxValue(), the string form comes from toString(), and hashCode() gives the hash code.
प्रश्न 8उत्तर + हल
wrapper class object का hash code पाने के लिए किस method का उपयोग होता है?
Which method is used to retrieve the hash code of a wrapper class object?
AvalueOf()
BhashCode()
CtoString()
DcompareTo()
सही उत्तर / Answer: (B)
हल / Solution
hashCode() method Object class से आता है, और हर wrapper class इसे अपने हिसाब से override करती है। जैसे Integer का hash code उसका int मान ही होता है। HashMap और HashSet जैसे collections इसी से object की जगह तय करते हैं। valueOf() object बनाता है, toString() String रूप देता है, और compareTo() दो objects की तुलना करता है। इसलिए सही उत्तर hashCode() है।
The hashCode() method comes from the Object class, and every wrapper class overrides it. For example, the hash code of an Integer is simply its int value. Collections such as HashMap and HashSet use it to decide where to store an object. valueOf() creates an object, toString() gives a String form, and compareTo() compares two objects. So the correct answer is hashCode().
प्रश्न 9उत्तर + हल
wrapper classes में toString() method क्या करता है?
What does the toString() method in wrapper classes do?
Awrapper class object को उसके hexadecimal string रूप में बदलता हैConverts a wrapper class object to its hexadecimal string representation
Bwrapper class object को उसके संगत primitive डेटा टाइप में बदलता हैConverts a wrapper class object to its corresponding primitive data type
Cwrapper class object का string रूप लौटाता हैReturns the string representation of a wrapper class object
Dwrapper class object का hash code लौटाता हैRetrieves the hash code of a wrapper class object
सही उत्तर / Answer: (C)
हल / Solution
toString() wrapper object में रखे मान को String के रूप में लौटाता है। जैसे Integer.valueOf(45).toString() का नतीजा "45" है, यानी दशमलव रूप, hexadecimal नहीं। hexadecimal के लिए toHexString() अलग method है। object से primitive निकालने का काम intValue() जैसे xxxValue() methods करते हैं। hash code के लिए hashCode() है। इसलिए toString() का सही वर्णन विकल्प 3 में है।
toString() returns the value stored in a wrapper object as a String. For example, Integer.valueOf(45).toString() gives "45", which is the decimal form, not hexadecimal. A separate method, toHexString(), handles hexadecimal output. Extracting a primitive from the object is done by xxxValue() methods such as intValue(). The hash code comes from hashCode(). So option 3 correctly describes toString().
प्रश्न 10उत्तर + हल
wrapper classes में valueOf() method क्या करता है?
What does the valueOf() method in wrapper classes do?
AString को उसके संगत primitive डेटा टाइप में बदलता हैConverts a string to its corresponding primitive data type
Bprimitive डेटा टाइप को उसकी संगत wrapper class के object में बदलता हैConverts a primitive data type to its corresponding wrapper class object
Cजाँचता है कि कोई object किसी ख़ास wrapper class का instance है या नहींChecks if an object is an instance of a specific wrapper class
Dwrapper class object का hash code लौटाता हैRetrieves the hash code of a wrapper class object
सही उत्तर / Answer: (B)
हल / Solution
valueOf() एक static method है, जो wrapper object लौटाता है। जैसे Integer.valueOf(7) एक Integer object देता है। यह String भी ले सकता है, पर तब भी नतीजा wrapper object ही होता है, primitive नहीं। String से primitive बनाने का काम parseXxx() करता है। instance जाँचने का काम instanceof करता है, और hash code hashCode() देता है। इसलिए विकल्प 2 सही है।
valueOf() is a static method that returns a wrapper object. For example, Integer.valueOf(7) returns an Integer object. It can also take a String, but even then the result is a wrapper object, not a primitive. Converting a String to a primitive is the job of parseXxx(). Checking the instance type is done by instanceof, and the hash code comes from hashCode(). So option 2 is the correct description.
आगे के 16 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति