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

Types of Variables in Java — प्रश्न और उत्तर

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

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

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

भाषा
प्रश्न 1उत्तर + हल
local variable को और किन नामों से जाना जाता है?
By what other names are local variables known?
  1. Aclass level variable या fieldClass level variable or field
  2. Bobject level variableObject level variable
  3. Ctemporary, stack या automatic variableTemporary, stack or automatic variable
  4. 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?
  1. Aकुछ नहीं — उसे सीधे इस्तेमाल किया जा सकता हैNothing — it can be used directly
  2. Bहर बार class का नाम लिखना पड़ता हैThe class name must be written every time
  3. Cपहले object बनाना पड़ता हैAn object must be created first
  4. 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?
  1. Aवह धीमा चलता हैIt runs slowly
  2. Bcompiler उसे मना करता हैThe compiler forbids it
  3. Cवह ज़्यादा memory लेता हैIt takes more memory
  4. 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);
  1. A3 0 छपेगाIt prints 3 0
  2. B3 3 छपेगाIt prints 3 3
  3. Cruntime errorA runtime error
  4. 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?
  1. Apublic
  2. Bstatic
  3. Cprotected
  4. 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?
  1. Aकिसी भी method के अंदरInside any method
  2. Bconstructor के अंदरInside a constructor
  3. Cकिसी block के अंदरInside a block
  4. 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?
  1. Aहमेशा compile time errorAlways a compile time error
  2. Bruntime errorA runtime error
  3. Cकोई error नहीं आतीNo error occurs
  4. 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?
  1. Aदोनों को class-level variableBoth are called class-level variables
  2. Binstance को stack variable, static को heap variableInstance as stack variable, static as heap variable
  3. Cinstance को object-level variable, static को class-level variableInstance as object-level variable, static as class-level variable
  4. 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?
  1. Aprimitive मान रखने के लिएTo hold primitive values
  2. Bसिर्फ़ संख्या गिनने के लिएOnly to count numbers
  3. Cobject का reference रखने के लिएTo hold the reference of an object
  4. 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?
  1. Ainstance variableAn instance variable
  2. Bstatic variableA static variable
  3. Clocal variableA local variable
  4. 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 — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 11उत्तर app में
JDK 8 आने से पहले और JDK 8 से, static variable कहाँ store होते हैं?
Before JDK 8 arrived and from JDK 8 onwards, where are static variables stored?
  1. Aपहले stack में, बाद में heap मेंIn the stack before, in the heap after
  2. Bपहले PermGen में, बाद में native memory के metaspace मेंIn PermGen before, in the metaspace of native memory after
  3. Cपहले heap में, बाद में stack मेंIn the heap before, in the stack after
  4. Dपहले PermGen में, बाद में Java heap परIn PermGen before, on the Java heap after
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 12उत्तर app में
static variable कब बनता है और कब नष्ट होता है?
When is a static variable created and when is it destroyed?
  1. Aobject बनने पर और object ख़त्म होने परOn object creation and on the object's end
  2. Bclass load होने पर और class unload होने परOn class loading and on class unloading
  3. Cmethod call होने पर और method ख़त्म होने परOn a method call and at the method's end
  4. Dprogram शुरू होने पर और program ख़त्म होने परAt program start and at program end
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 13उत्तर app में
instance variable को static area (static method) से सीधे access किया जा सकता है?
Can an instance variable be accessed directly from the static area (a static method)?
  1. Aनहीं — उसके लिए object चाहिएNo — an object is needed for that
  2. Bहाँ, सीधेYes, directly
  3. Cहाँ, पर सिर्फ़ final हो तोYes, but only if it is final
  4. Dहाँ, class के नाम सेYes, with the class name
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
Instance variable की कितनी copy बनती हैं और वे कहाँ संग्रहीत होती हैं?
How many copies of an instance variable are made, and where are they stored?
  1. Aहर object में एक copy, heap memory मेंOne copy in each object, in heap memory
  2. Bपूरी class के लिए एक copy, stack मेंOne copy for the whole class, in the stack
  3. Cहर object में एक copy, stack मेंOne copy in each object, in the stack
  4. Dपूरी class के लिए एक copy, heap मेंOne copy for the whole class, in the heap
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 15उत्तर app में
declaration और behaviour के आधार पर Java के variable कितने भागों में बाँटे गए हैं?
On the basis of declaration and behaviour, into how many kinds are Java's variables divided?
  1. Aतीन — Instance, Static और LocalThree — instance, static and local
  2. Bदो — Primitive और ReferenceTwo — primitive and reference
  3. CचारFour
  4. DपाँचFive
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
एक्सेस मॉडिफ़ायर्स का उपयोग लोकल वेरिएबल के लिए नहीं किया जा सकता है।
Access modifiers cannot be used for local variables.
  1. AहाँYes
  2. BनहींNo
  3. Cहाँ या नहीं, दोनों हो सकता हैCan be yes or no
  4. Dकह नहीं सकतेCan not say
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
स्टैटिक वेरिएबल्स को किसके साथ कॉल करके एक्सेस किया जा सकता है?
Static variables can be accessed by calling with the?
  1. Aऑब्जेक्ट का नामObject name
  2. Bक्लास का नामClass name
  3. Cफ़ंक्शन का नामFunction name
  4. DA और B दोनोंBoth A & B
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 20उत्तर app में
किन वेरिएबल्स का कोई डिफ़ॉल्ट मान नहीं होता है?
Which variables have no default values?
  1. Aस्टैटिक वेरिएबल्सStatic Variables
  2. Bइंस्टेंस वेरिएबल्सInstance Variables
  3. Cलोकल वेरिएबलLocal Variable
  4. DA और B दोनोंBoth A and B
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
Types of Variables in Java के सभी 21 प्रश्न — उत्तर, हल और अभ्यास

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

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

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

Java के दूसरे topics

सभी topics