पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 10 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
अगर डेटा सदस्य private हैं, तो class object से उन्हें एक्सेस करने के लिए हम क्या कर सकते हैं?
If data members are private, what can we do to access them from the class object?
Aprivate डेटा सदस्यों को क्लास के बाहर से कभी एक्सेस नहीं किया जा सकताPrivate data members can never be accessed from outside the class
Bउन डेटा सदस्यों को एक्सेस करने के लिए public member functions बनाएँCreate public member functions to access those data members
Cउन डेटा सदस्यों को एक्सेस करने के लिए private member functions बनाएँCreate private member functions to access those data members
Dउन डेटा सदस्यों को एक्सेस करने के लिए protected member functions बनाएँCreate protected member functions to access those data members
सही उत्तर / Answer: (B)
हल / Solution
private सदस्य सिर्फ़ अपनी क्लास के अंदर दिखते हैं। बाहर से object के ज़रिए उन्हें सीधे नहीं पढ़ा जा सकता। इसलिए क्लास में public मेथड बनाए जाते हैं, जैसे getName() और setName()। ये मेथड क्लास के अंदर हैं, इसलिए private डेटा पढ़ और बदल सकते हैं। private मेथड भी बाहर से नहीं दिखते। protected मेथड हर जगह से नहीं दिखते। विकल्प 1 ग़लत है, क्योंकि public मेथड से पहुँच मिल जाती है।
Private members are visible only inside their own class. They cannot be read directly through an object from outside. So public methods are written in the class, such as getName() and setName(). These methods are inside the class, so they can read and change the private data. Private methods are also hidden from outside. Protected methods are not visible everywhere. Option 1 is wrong because public methods give access.
प्रश्न 2उत्तर + हल
स्टैटिक वेरिएबल डिक्लेयर करने के लिए किस keyword का उपयोग किया जाना चाहिए?
Which keyword should be used to declare static variables?
Aconst
Bcommon
Cstatic
Dstat
सही उत्तर / Answer: (C)
हल / Solution
जावा में स्टैटिक वेरिएबल static keyword से डिक्लेयर होता है, जैसे static int count = 0; लिखना। ऐसा वेरिएबल पूरी क्लास का होता है और सभी objects इसकी एक ही copy साझा करते हैं। const जावा में reserved शब्द है, पर उसका कोई उपयोग नहीं होता। common और stat जावा के keywords ही नहीं हैं। इसलिए सही उत्तर static है और बाक़ी तीनों विकल्प ग़लत हैं।
In Java, a static variable is declared with the static keyword, as in static int count = 0;. Such a variable belongs to the whole class, and all objects share one copy of it. const is a reserved word in Java, but it has no use. common and stat are not Java keywords at all. So the correct answer is static, and the other three options are wrong.
प्रश्न 3उत्तर + हल
किस प्रक्रिया में लोकल वेरिएबल का नाम किसी इंस्टेंस वेरिएबल के नाम जैसा होता है?
In which process, a local variable has the same name as one of the instance variables?
Aसीरियलाइज़ेशनSerialization
Bवेरिएबल शैडोइंगVariable Shadowing
Cएब्स्ट्रैक्शनAbstraction
Dमल्टी-थ्रेडिंगMulti-threading
सही उत्तर / Answer: (B)
हल / Solution
जब किसी मेथड का लोकल वेरिएबल या parameter किसी इंस्टेंस वेरिएबल के नाम जैसा हो, तो उस मेथड में लोकल वेरिएबल इंस्टेंस वेरिएबल को ढक लेता है। इसे वेरिएबल शैडोइंग कहते हैं। तब इंस्टेंस वेरिएबल तक पहुँचने के लिए this.name लिखना पड़ता है। सीरियलाइज़ेशन object को byte stream में बदलना है। एब्स्ट्रैक्शन ज़रूरी बातें दिखाकर बाक़ी छिपाना है। मल्टी-थ्रेडिंग कई काम साथ चलाना है।
When a local variable or a parameter in a method has the same name as an instance variable, the local variable hides the instance variable inside that method. This is called variable shadowing. To reach the instance variable, we then write this.name. Serialization turns an object into a byte stream. Abstraction shows only the needed details and hides the rest. Multi-threading runs many tasks at the same time.
प्रश्न 4उत्तर + हल
किसी एक प्रकार के एक से ज़्यादा वेरिएबल डिक्लेयर करने के लिए हम __________ सूची का उपयोग कर सकते हैं।
To declare more than one variable of the specified type, we can use a __________ list.
Aकोलन से अलग (colon-separated)colon-separated
Bकोष्ठक से अलग (bracket-separated)bracket-separated
Cकॉमा से अलग (comma-separated)comma-separated
Dइनमें से कोई नहींNone of the above
सही उत्तर / Answer: (C)
हल / Solution
जावा में एक ही प्रकार के कई वेरिएबल एक ही पंक्ति में डिक्लेयर किए जा सकते हैं। इसके लिए नामों को कॉमा से अलग किया जाता है, जैसे int a, b, c; या int x = 5, y = 10; लिखना। कोलन का उपयोग switch के case और labels में होता है, डिक्लेरेशन में नहीं। कोष्ठक array और मेथड के लिए होते हैं। इसलिए सही उत्तर कॉमा से अलग सूची है।
In Java, several variables of the same type can be declared on one line. The names are separated by commas, as in int a, b, c; or int x = 5, y = 10;. A colon is used in switch case labels and loop labels, not in declarations. Brackets are used for arrays and methods. So the correct answer is a comma-separated list, and options 1, 2 and 4 are wrong.
प्रश्न 5उत्तर + हल
एक ________ हमें नाम वाली स्टोरेज (memory की जगह) देता है, जिसे हमारा प्रोग्राम बदल सकता है।
A ________ provides us with named storage that our programs can manipulate.
Aडेटा टाइपdata type
Bकॉन्स्टैंट्सconstants
Cऑपरेटर्सoperators
Dवेरिएबलvariable
सही उत्तर / Answer: (D)
हल / Solution
वेरिएबल memory की एक जगह का नाम होता है। प्रोग्राम उस नाम से वहाँ रखा मान पढ़ सकता है और बदल भी सकता है। जैसे int age = 20; में age एक वेरिएबल है। डेटा टाइप सिर्फ़ यह बताता है कि किस तरह का मान रखा जाएगा और कितनी जगह लगेगी। कॉन्स्टैंट का मान बदला नहीं जा सकता। ऑपरेटर्स गणना करते हैं, मान नहीं रखते।
A variable is a name given to a place in memory. The program can read the value stored there and also change it using that name. For example, in int age = 20; age is a variable. A data type only tells what kind of value is stored and how much space it needs. A constant's value cannot be changed. Operators do calculations; they do not store values.
प्रश्न 6उत्तर + हल
कौन-सा वेरिएबल नाम अवैध (invalid) है?
Which is the invalid variable name?
A1stLevel
Bfirst Level
C*firstLevel
Dउपरोक्त सभीAll of Above
सही उत्तर / Answer: (D)
हल / Solution
तीनों नाम जावा के नियम तोड़ते हैं। 1stLevel अंक से शुरू होता है, जबकि नाम अंक से शुरू नहीं हो सकता। first Level में बीच में space है, और नाम में space की अनुमति नहीं है। *firstLevel में * चिह्न है, जबकि सिर्फ़ _ और $ जैसे चिह्न ही चल सकते हैं। तीनों अवैध हैं, इसलिए सही उत्तर 'उपरोक्त सभी' है।
All three names break Java's naming rules. 1stLevel starts with a digit, but a name cannot start with a digit. first Level has a space in the middle, and spaces are not allowed in a name. *firstLevel has the * sign, but only special characters like _ and $ are allowed. All three are invalid, so the correct answer is 'All of Above'.
प्रश्न 7उत्तर + हल
कौन-सा वेरिएबल नाम वैध है?
Which is the valid variable name?
A5thTeam
B&5thteam
C_5thTeam
Dइनमें से कोई नहींNone of Above
सही उत्तर / Answer: (C)
हल / Solution
जावा में वेरिएबल का नाम अक्षर, underscore (_) या डॉलर चिह्न ($) से शुरू होना चाहिए। उसके बाद अंक आ सकते हैं। _5thTeam underscore से शुरू होता है, इसलिए यह वैध नाम है। 5thTeam अंक से शुरू होता है, इसलिए अवैध है। &5thteam में & चिह्न है, जो नाम में आ ही नहीं सकता। एक विकल्प वैध है, इसलिए 'इनमें से कोई नहीं' भी ग़लत है।
In Java, a variable name must start with a letter, an underscore (_) or a dollar sign ($). Digits can come after that. _5thTeam starts with an underscore, so it is a valid name. 5thTeam starts with a digit, so it is invalid. &5thteam contains the & sign, which is never allowed in a name. Since one option is valid, 'None of Above' is also wrong.
प्रश्न 8उत्तर + हल
वेरिएबल का नाम किससे शुरू नहीं होना चाहिए?
A variable name should not begin with
Aकिसी अंक सेA number
Bunderscore और डॉलर चिह्न को छोड़कर किसी विशेष चिह्न सेSpecial characters but underscore and dollar sign
CA और B दोनोंBoth A and B
Dकेवल AOnly A
सही उत्तर / Answer: (C)
हल / Solution
जावा में वेरिएबल का नाम अक्षर, underscore (_) या डॉलर चिह्न ($) से शुरू हो सकता है। नाम किसी अंक से शुरू नहीं हो सकता, जैसे 5count ग़लत है। _ और $ के अलावा कोई विशेष चिह्न, जैसे @, # या *, भी शुरुआत में नहीं आ सकता। यानी A और B दोनों नियम सही हैं। 'केवल A' अधूरा है, इसलिए उत्तर 'A और B दोनों' है।
In Java, a variable name can start with a letter, an underscore (_) or a dollar sign ($). It cannot start with a digit, so 5count is invalid. Apart from _ and $, no special character such as @, # or * can come at the start. So both rule A and rule B are correct. 'Only A' is incomplete, so the answer is 'Both A and B'.
प्रश्न 9उत्तर + हल
इंस्टेंस वेरिएबल कहाँ डिक्लेयर किए जाते हैं?
Where to declare instance variable?
Aयह क्लास के अंदर और मेथड के बाहर डिक्लेयर होता है।It declares inside the class and outside of method.
Bयह static के साथ क्लास के अंदर और मेथड के बाहर डिक्लेयर होता है।It declares inside the class with static prefix and outside of method.
Cयह मेथड के अंदर डिक्लेयर होता है।It declares inside the method.
Dकोई नहींNone
सही उत्तर / Answer: (A)
हल / Solution
इंस्टेंस वेरिएबल क्लास के अंदर, पर किसी भी मेथड, कंस्ट्रक्टर या ब्लॉक के बाहर डिक्लेयर किया जाता है। इसके साथ static नहीं लगता। इसलिए हर object को इसकी अपनी अलग copy मिलती है। अगर इसी जगह static लगा दें, तो यह क्लास वेरिएबल बन जाता है। मेथड के अंदर डिक्लेयर वेरिएबल लोकल वेरिएबल होता है। इसलिए सही उत्तर विकल्प 1 है।
An instance variable is declared inside the class but outside every method, constructor or block. It does not use the static keyword. So each object gets its own separate copy of it. If static is added in the same place, it becomes a class variable. A variable declared inside a method is a local variable. So options 2 and 3 describe other variables, and the correct answer is option 1.
प्रश्न 10उत्तर + हल
जावा में object बनाते समय उसके instance variable को आरंभ (initialize) करने के लिए निम्नलिखित में से किसका उपयोग किया जाता है?
In Java, which of the following is used to initialize an instance variable of an object during object creation?
Aकंस्ट्रक्टरConstructor
Bfinalize()
Cnew
Dthis
सही उत्तर / Answer: (A)
हल / Solution
कंस्ट्रक्टर एक ख़ास मेथड है, जिसका नाम क्लास के नाम जैसा होता है। object बनते ही यह अपने-आप चलता है। इसका मुख्य काम instance variables को शुरुआती मान देना है। new keyword object के लिए memory देता है और कंस्ट्रक्टर को बुलाता है, पर मान ख़ुद नहीं देता। this सिर्फ़ मौजूदा object का reference है। finalize() object हटने से पहले चलता था। इसलिए उत्तर कंस्ट्रक्टर है।
A constructor is a special method whose name is the same as the class name. It runs automatically when an object is created. Its main job is to give starting values to instance variables. The new keyword gives memory to the object and calls the constructor, but it does not set values itself. this is only a reference to the current object. finalize() ran before an object was removed. So the answer is constructor.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
जावा में लोकल वेरिएबल का दायरा (scope) क्या होता है?
What is the scope of a local variable in Java?
Aयह पूरे प्रोग्राम में कहीं भी उपयोग हो सकता है।It is accessible throughout the entire program.
Bयह सिर्फ़ उसी मेथड या ब्लॉक के अंदर उपयोग हो सकता है जिसमें इसे डिक्लेयर किया गया है।It is accessible only within the method or block in which it is declared.
Cयह उसी क्लास और उसकी subclasses में उपयोग हो सकता है।It is accessible within the same class and its subclasses.
Dयह पूरे package में उपयोग हो सकता है।It is accessible throughout the entire package.
जावा में इंस्टेंस वेरिएबल्स के बारे में क्या सही है?
What is true about Instance Variables in java?
Aइंस्टेंस वेरिएबल्स क्लास में डिक्लेयर किए जाते हैंInstance variables are declared in a class
Bजब heap में किसी object के लिए जगह दी जाती है, तब हर इंस्टेंस वेरिएबल के मान के लिए एक खाना (slot) बनता है।When a space is allocated for an object in the heap, a slot for each instance variable value is created.
Cइंस्टेंस वेरिएबल्स को क्लास स्तर पर उपयोग से पहले या बाद में डिक्लेयर किया जा सकता हैInstance variables can be declared in class level before or after use