पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 11 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
local variable को और किन नामों से जाना जाता है?
By what other names are local variables known?
Aclass level variable या fieldClass level variable or field
Bobject level variableObject level variable
Ctemporary, stack या automatic variableTemporary, stack or automatic variable
Dreference variableReference variable
सही उत्तर / Answer: (C)
हल / Solution
पाठ कहता है कि method, block या constructor के अंदर declare किए गए variable को local variable या temporary variable या stack variable या automatic variable कहा जाता है। «object level» नाम instance variable का है और «class level या field» static variable का। reference variable तो पहले बँटवारे की श्रेणी है, जो primitive के मुक़ाबले खड़ी है।
The text says a variable declared inside a method, block or constructor is called a local variable, or a temporary variable, or a stack variable, or an automatic variable. The name 'object level' belongs to the instance variable and 'class level or field' to the static one. A reference variable is a category of the first division, standing opposite the primitive.
प्रश्न 2उत्तर + हल
static variable को उसी class के भीतर इस्तेमाल करना हो तो क्या करना पड़ता है?
To use a static variable inside its own class, what has to be done?
Aकुछ नहीं — उसे सीधे इस्तेमाल किया जा सकता हैNothing — it can be used directly
Bहर बार class का नाम लिखना पड़ता हैThe class name must be written every time
Cपहले object बनाना पड़ता हैAn object must be created first
Dउसे final बनाना पड़ता हैIt must be made final
सही उत्तर / Answer: (A)
हल / Solution
पाठ कहता है कि static variable को object reference से या class के नाम से access किया जा सकता है, पर यदि उसे उसी class में काम में लेना हो तो class के नाम की ज़रूरत नहीं होती — वह सीधे इस्तेमाल हो जाता है। object बनाना instance variable के लिए ज़रूरी होता है, static के लिए नहीं।
The text says a static variable may be accessed through an object reference or by the class name, but if it is to be used inside that same class the class name is not needed — it can be used directly. Creating an object is required for an instance variable, not for a static one.
प्रश्न 3उत्तर + हल
logical block के अंदर local variable को initialise करने की सलाह क्यों नहीं दी जाती?
Why is initialising a local variable inside a logical block not advised?
Aवह धीमा चलता हैIt runs slowly
Bcompiler उसे मना करता हैThe compiler forbids it
Cवह ज़्यादा memory लेता हैIt takes more memory
Dइसकी कोई गारंटी नहीं कि वह block चलेगा ही — न चले तो runtime error की सम्भावना रहती हैThere is no guarantee the block will run at all — if it does not, a runtime error becomes possible
सही उत्तर / Answer: (D)
हल / Solution
पाठ का Note 1 — logical block के अंदर local variable का initialisation नहीं करना चाहिए, क्योंकि इसकी कोई गारंटी नहीं कि वह block run time पर चलेगा ही; न चले तो variable बिना मान रह जाता है और error की सम्भावना बनती है। Note 2 इसीलिए सुझाता है कि local variable को declare करते समय ही उसके default मान से initialise कर दीजिए।
The text's Note 1 — a local variable should not be initialised inside a logical block, because there is no guarantee that the block will run at run time; if it does not, the variable is left without a value and an error becomes possible. Note 2 therefore advises initialising a local variable with its default value at the time of declaring it.
प्रश्न 4उत्तर + हल
नीचे के code में «S.o.p(i+" "+j);» पर क्या होगा?
int i=0;
for(int j=0; j<3; j++){
i=i+j;
}
S.o.p(i+" "+j);
What happens at 'S.o.p(i+" "+j);' in the code below?
int i=0;
for(int j=0; j<3; j++){
i=i+j;
}
S.o.p(i+" "+j);
A3 0 छपेगाIt prints 3 0
B3 3 छपेगाIt prints 3 3
Cruntime errorA runtime error
Dcompile time error — j का scope for तक ही थाA compile time error — j's scope was limited to the for loop
सही उत्तर / Answer: (D)
हल / Solution
j को for की कोष्ठक में declare किया गया है, सो उसका scope उसी loop तक सीमित है। loop के बाहर उसे छापने पर पाठ के अनुसार «CTE: cannot find symbol (symbol: variable j, location: class Test)» मिलती है। यही वह नियम है कि local variable का scope उस block तक ही रहता है जिसमें उसे declare किया गया हो, और block ख़त्म होते ही वह stack से हट जाता है।
j is declared in the for statement's parentheses, so its scope is limited to that loop alone. Printing it outside the loop gives, per the text, 'CTE: cannot find symbol (symbol: variable j, location: class Test)'. This is the very rule that a local variable's scope stays within the block in which it was declared, and that it is removed from the stack as soon as that block ends.
प्रश्न 5उत्तर + हल
local variable पर कौन-सा एक modifier लगाया जा सकता है?
Which single modifier may be applied to a local variable?
Apublic
Bstatic
Cprotected
Dfinal
सही उत्तर / Answer: (D)
हल / Solution
पाठ का Note 3 — local variable के लिए केवल final modifier काम में लिया जा सकता है; कोई दूसरा लगाने पर compile time error आती है, क्योंकि local variable को उसी block के भीतर ही access किया जा सकता है, सो access modifier का कोई अर्थ ही नहीं बनता। «न लिखने पर default modifier» वाला नियम सिर्फ़ instance और static variable पर लागू है।
The text's Note 3 — only final may be used as a modifier for a local variable; applying any other gives a compile time error, because a local variable can be accessed only within its own block, so an access modifier would carry no meaning. The rule that an unwritten modifier becomes 'default' applies only to instance and static variables.
प्रश्न 6उत्तर + हल
instance और static variable class में कहाँ declare किए जाते हैं?
Where are instance and static variables declared within a class?
Aकिसी भी method के अंदरInside any method
Bconstructor के अंदरInside a constructor
Cकिसी block के अंदरInside a block
Dसीधे class के भीतर — block, method या constructor में नहींDirectly within the class — not in a block, method or constructor
सही उत्तर / Answer: (D)
हल / Solution
पाठ दोनों के लिए यही कहता है — instance variable सीधे class में declare किए जाते हैं, किसी block, method या constructor में नहीं; और static variable भी सीधे class के भीतर, block, method तथा constructor के भीतर नहीं। जो variable इनके अंदर declare होता है वह local कहलाता है, और उसका scope उसी block तक सीमित रहता है।
The text says this for both — instance variables are declared directly in the class and not in any block, method or constructor; and static variables likewise directly within the class, not inside a block, method or constructor. A variable declared inside those is called a local one, and its scope stays limited to that block alone.
प्रश्न 7उत्तर + हल
local variable को बिना initialise किए declare कर दिया जाए पर program में कहीं उपयोग न किया जाए, तो क्या होगा?
If a local variable is declared without initialisation but is never used anywhere in the program, what happens?
Aहमेशा compile time errorAlways a compile time error
Bruntime errorA runtime error
Cकोई error नहीं आतीNo error occurs
DJVM उसे 0 कर देता हैThe JVM sets it to 0
सही उत्तर / Answer: (C)
हल / Solution
पाठ का उदाहरण 1 यही दिखाता है — «int i;» लिखकर सिर्फ़ «Hello» छापने पर output ठीक «Hello» आता है, कोई error नहीं। error तब आती है जब उसे उपयोग किया जाए: उदाहरण 2 में «S.o.p(i);» पर «variable i might not have been initialized» मिलती है। JVM local variable को default मान देता ही नहीं।
The text's example 1 shows exactly this — writing 'int i;' and printing only 'Hello' gives the output 'Hello' with no error at all. The error appears only when the variable is used: in example 2, 'S.o.p(i);' gives 'variable i might not have been initialized'. The JVM does not give a local variable any default value, unlike an instance or static variable, which is why the compiler insists on it.
प्रश्न 8उत्तर + हल
instance variable को और किस नाम से जाना जाता है, और static variable को?
By what other name is an instance variable known, and a static variable?
Aदोनों को class-level variableBoth are called class-level variables
Binstance को stack variable, static को heap variableInstance as stack variable, static as heap variable
Cinstance को object-level variable, static को class-level variableInstance as object-level variable, static as class-level variable
Dinstance को class-level, static को object-levelInstance as class-level, static as object-level
सही उत्तर / Answer: (C)
हल / Solution
पाठ के शब्दों में — instance variable को object level variable भी कहा जाता है और static variable को class-level variable या field। नाम अर्थ से ही निकलते हैं: instance हर object का अपना होता है, इसलिए object का नाम लगा; static पूरी class का साझा होता है, इसलिए class का। local variable को temporary, stack या automatic variable कहा जाता है।
In the text's words — an instance variable is also called an object level variable and a static variable a class-level variable or field. The names follow from the meaning: an instance one belongs to each object, hence the object's name; a static one is shared by the whole class, hence the class's. A local variable is called a temporary, stack or automatic variable.
प्रश्न 9उत्तर + हल
Reference variable का उपयोग किसलिए होता है?
What is a reference variable used for?
Aprimitive मान रखने के लिएTo hold primitive values
Bसिर्फ़ संख्या गिनने के लिएOnly to count numbers
Cobject का reference रखने के लिएTo hold the reference of an object
Dmemory मुक्त करने के लिएTo free memory
सही उत्तर / Answer: (C)
हल / Solution
पहले बँटवारे के अनुसार Primitive variable primitive data type को दर्शाते हैं, जैसे int, float, double और char, और Reference variable का उपयोग object का reference रखने में होता है। पाठ का उदाहरण — «Student s = new Student();» में s reference variable है जो Student type के object को point कर रहा है, और उसका डिफ़ॉल्ट मान null होता है।
By the first division, primitive variables represent the primitive data types, such as int, float, double and char, while a reference variable is used to hold the reference of an object. The text's example — in 'Student s = new Student();' the s is a reference variable pointing to an object of the Student type, and its default value is null.
प्रश्न 10उत्तर + हल
किसी variable की वैल्यू उस class के हर object के लिए एक ही रखनी हो तो उसे क्या बनाना चाहिए?
If a variable's value is to be the same for every object of the class, what should it be made?
Ainstance variableAn instance variable
Bstatic variableA static variable
Clocal variableA local variable
Dfinal variableA final variable
सही उत्तर / Answer: (B)
हल / Solution
पाठ का नियम — यदि किसी variable की वैल्यू उस class के हर एक object के लिए एक ही हो तो उसे instance variable नहीं, static बनाना चाहिए। कारण साफ़ है: instance variable की copy हर object में अलग बनती है, जबकि static की एक ही copy बनती है और सारे object उससे जुड़ जाते हैं।
The text's rule — if a variable's value is the same for every object of the class, it should be made static rather than an instance variable. The reason is plain: a separate copy of an instance variable is made in each object, whereas a static one has a single copy to which all objects are connected.
आगे के 11 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति