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

Import and Static Import — प्रश्न और उत्तर

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

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

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

भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित में से कौन-सा import स्टेटमेंट मान्य (valid) है?
Which of the following import statements is valid?
  1. Aimport static java.lang.Math.sqrt();
  2. Bimport java.lang;
  3. Cimport java.lang.*;
  4. Dimport static java.lang;

सही उत्तर / Answer: (C)

हल / Solution
import java.lang.*; मान्य है। यह java.lang की सभी public क्लासेज़ लाता है। यह वैसे भी अपने आप import होता है, पर लिखना ग़लत नहीं। static import में सिर्फ़ मेथड का नाम लिखा जाता है, कोष्ठक नहीं, इसलिए sqrt() वाला रूप error देता है। import java.lang; ग़लत है, क्योंकि पैकेज को * के बिना import नहीं किया जा सकता। import static सिर्फ़ किसी क्लास से होता है, पैकेज से नहीं, इसलिए चौथा रूप भी ग़लत है।
The statement import java.lang.*; is valid; it brings all public classes of java.lang, which is imported automatically anyway, but writing it is not an error. A static import names only the method, without parentheses, so the sqrt() form fails. The form import java.lang; is wrong because a package cannot be imported without the star. A static import must come from a class, not a package, so the fourth form is also invalid.
प्रश्न 2उत्तर + हल
यदि एक ही प्रोग्राम में अलग-अलग क्लासों के एक ही नाम वाले static सदस्य हों, तो static सदस्यों को ढूँढ़ते समय प्राथमिकता क्रम क्या होता है?
What is the precedence order while resolving static members if we have same-name static members of different classes in the same program?
  1. A1. मौजूदा क्लास के static सदस्य 2. स्पष्ट (explicit) static import 3. अस्पष्ट (implicit) static import1. Current class static members 2. Explicit static import 3. Implicit static import
  2. B1. स्पष्ट (explicit) static import 2. मौजूदा क्लास के static सदस्य 3. अस्पष्ट (implicit) static import1. Explicit static import 2. Current class static members 3. Implicit static import
  3. C1. अस्पष्ट (implicit) static import 2. स्पष्ट (explicit) static import 3. मौजूदा क्लास के static सदस्य1. Implicit static import 2. Explicit static import 3. Current class static members
  4. D1. स्पष्ट (explicit) static import 2. अस्पष्ट (implicit) static import 3. मौजूदा क्लास के static सदस्य1. Explicit static import 2. Implicit static import 3. Current class static members

सही उत्तर / Answer: (A)

हल / Solution
static सदस्य का नाम ढूँढ़ते समय कम्पाइलर सबसे पहले मौजूदा क्लास में देखता है। क्लास में घोषित static field बाहर से import किए गए उसी नाम के सदस्य को ढक देता है। उसके बाद explicit static import आता है, जैसे import static java.lang.Integer.MAX_VALUE; और सबसे आख़िर में * वाला implicit static import, जैसे import static java.lang.Byte.*; इसलिए सही क्रम मौजूदा क्लास, explicit, फिर implicit है।
When resolving a static member name, the compiler looks first in the current class. A static field declared in the class hides any imported member with the same name. Next comes the explicit static import, such as import static java.lang.Integer.MAX_VALUE; and last the implicit on-demand import with *, such as import static java.lang.Byte.*; So the order is current class members, explicit static import, then implicit static import.
प्रश्न 3उत्तर + हल
पूर्णतः योग्य नाम (fully qualified name) के बारे में कौन-सा कथन असत्य है?
Which statement is false about fully qualified name?
  1. Aपूर्णतः योग्य नाम का उपयोग करने पर import स्टेटमेंट लिखने की ज़रूरत नहीं होती।No need to write import statement in fully qualified name.
  2. Bपूर्णतः योग्य नाम कोड की लंबाई बढ़ाता है।fully qualified name increases the length of the code.
  3. Cपूर्णतः योग्य नाम कोड की लंबाई घटाता है।fully qualified name decreases the length of the code.
  4. Dनामों में अस्पष्टता (ambiguity) होने पर पूर्णतः योग्य नाम कारगर है।fully qualified name is effective in the case of ambiguity.

सही उत्तर / Answer: (C)

हल / Solution
पूर्णतः योग्य नाम में पैकेज समेत क्लास का पूरा नाम लिखा जाता है, जैसे java.util.ArrayList list = new java.util.ArrayList(); इसमें import की ज़रूरत नहीं पड़ती। पर हर जगह पूरा नाम लिखने से कोड लंबा होता है। जब दो पैकेज में एक ही नाम की क्लास हो, जैसे दो Date, तब यही तरीका उलझन दूर करता है। इसलिए पहला, दूसरा और चौथा कथन सही हैं। कोड की लंबाई घटने वाला तीसरा कथन असत्य है।
A fully qualified name writes the class with its package, as in java.util.ArrayList list = new java.util.ArrayList(); so no import is needed. But writing the full name everywhere makes the code longer, not shorter. When two packages have classes with the same name, such as two Date classes, the full name removes the ambiguity. So statements one, two and four are true, and the claim that it decreases code length is false.
प्रश्न 4उत्तर + हल
किन पैकेजों को इम्पोर्ट करने की आवश्यकता नहीं होती?
Which packages do we not need to import?
  1. Ajava.util पैकेजjava.util package
  2. Bjava.lang पैकेजjava.lang package
  3. Cमौजूदा (current) पैकेजcurrent package
  4. Db और c दोनोंBoth b and c

सही उत्तर / Answer: (D)

हल / Solution
Java हर फ़ाइल में java.lang पैकेज अपने आप import कर देता है। इसी वजह से String, System, Math और Integer जैसी क्लासेज़ बिना import के चल जाती हैं। अपने ही पैकेज की क्लासेज़ भी एक-दूसरे को बिना import के दिखती हैं। पर java.util अपने आप नहीं आता। ArrayList या Scanner के लिए import java.util.*; या उस क्लास का import लिखना पड़ता है। इसलिए b और c दोनों सही हैं।
Java automatically imports the java.lang package into every source file, which is why String, System, Math and Integer work without an import. Classes of the current package also see each other without any import. But java.util is not imported automatically; ArrayList or Scanner needs import java.util.*; or an import of that class. So both b (java.lang) and c (current package) are correct, and the answer is Both b and c.
प्रश्न 5उत्तर + हल
अपने प्रोग्राम में Pattern क्लास का उपयोग करने के लिए कौन-सा इम्पोर्ट स्टेटमेंट आवश्यक है?
To use the Pattern class in our program, which import statement is required?
  1. Aimport java.*;
  2. Bimport java.util.*;
  3. Cimport java.util.regex.*;
  4. Dकोई इम्पोर्ट ज़रूरी नहींNo import required

सही उत्तर / Answer: (C)

हल / Solution
Pattern क्लास regular expression के लिए है और java.util.regex पैकेज में रहती है। इसलिए import java.util.regex.*; या import java.util.regex.Pattern; लिखना पड़ता है। import java.util.*; काफ़ी नहीं है, क्योंकि * सिर्फ़ उसी पैकेज की क्लासेज़ लाता है, सब-पैकेज की नहीं। import java.*; भी काम नहीं करता, क्योंकि java पैकेज में सीधे कोई क्लास नहीं है। Pattern java.lang में नहीं है, इसलिए बिना import के नहीं चलेगी।
The Pattern class handles regular expressions and lives in the java.util.regex package, so you need import java.util.regex.*; or import java.util.regex.Pattern; Writing import java.util.*; is not enough, because the star brings only classes of that package, not of its sub-packages. Writing import java.*; also fails, since the java package has no classes directly. Pattern is not in java.lang, so it cannot be used without an import.
प्रश्न 6उत्तर + हल
यदि एक ही प्रोग्राम में अलग-अलग पैकेज की एक ही नाम वाली क्लासेज़ का उपयोग करें, तो क्लास का नाम ढूँढ़ते समय पैकेजों का प्राथमिकता क्रम क्या होता है?
What is the precedence order of packages while resolving class names if we use same-name classes of different packages in the same program?
  1. A1. स्पष्ट (explicit) क्लास इम्पोर्ट 2. मौजूदा पैकेज 3. अस्पष्ट (implicit) क्लास इम्पोर्ट1. Explicit class import 2. Current Package 3. Implicit class import
  2. B1. मौजूदा पैकेज 2. स्पष्ट (explicit) क्लास इम्पोर्ट 3. अस्पष्ट (implicit) क्लास इम्पोर्ट1. Current Package 2. Explicit class import 3. Implicit class import
  3. C1. अस्पष्ट (implicit) क्लास इम्पोर्ट 2. मौजूदा पैकेज 3. स्पष्ट (explicit) क्लास इम्पोर्ट1. Implicit class import 2. Current Package 3. Explicit class import
  4. D1. स्पष्ट (explicit) क्लास इम्पोर्ट 2. अस्पष्ट (implicit) क्लास इम्पोर्ट 3. मौजूदा पैकेज1. Explicit class import 2. Implicit class import 3. Current Package

सही उत्तर / Answer: (A)

हल / Solution
explicit import का मतलब है एक क्लास का नाम लेकर import, जैसे import java.util.Date; implicit import * वाला रूप है। कम्पाइलर पहले explicit import देखता है। वह मौजूदा पैकेज की उसी नाम की क्लास को ढक देता है। फिर मौजूदा पैकेज की क्लासेज़ आती हैं। वे * से आई क्लासेज़ को ढक देती हैं। सबसे आख़िर में * वाले import देखे जाते हैं। इसलिए क्रम explicit, मौजूदा पैकेज, फिर implicit है।
An explicit import names one class, like import java.util.Date; while an implicit import uses the * form. The compiler first uses the explicit import, which hides a same-name class of the current package. Next come the classes of the current package, which hide any class brought in by a * import. The on-demand * imports are checked last. So the order is explicit import, current package, then implicit import.
प्रश्न 7उत्तर + हल
यदि एक ही नाम की क्लास कई पैकेजों में उपलब्ध हो, तो क्या होगा?
What if a class with the same name is available in multiple packages?
  1. Aकोई समस्या नहीं, कम्पाइलर इसे अपने आप सुलझा लेगा।No issue, the compiler will resolve this automatically.
  2. Bइस स्थिति में हमें पूर्णतः योग्य नाम (fully qualified name) का उपयोग करना पड़ेगा।We have to use fully qualified name in this case.
  3. Cहम दोनों क्लासेज़ का एक साथ उपयोग नहीं कर सकते।We can't use both classes simultaneously.
  4. Dइम्पोर्ट स्टेटमेंट से हम इसे सुलझा सकते हैं।Using an import statement we can resolve this.

सही उत्तर / Answer: (B)

हल / Solution
मान लीजिए java.util और java.sql दोनों में Date क्लास है। दोनों को * से import करके सिर्फ़ Date लिखें, तो कम्पाइलर reference to Date is ambiguous error देता है। यानी वह अपने आप नहीं चुनता। दोनों को एक साथ इस्तेमाल करने का तरीका पूरा नाम लिखना है, जैसे java.util.Date और java.sql.Date। import से एक ही Date को छोटा नाम मिल सकता है, दूसरी के लिए पूरा नाम लिखना ही पड़ता है।
Suppose both java.util and java.sql have a Date class. If both are imported with * and you write just Date, the compiler reports that the reference to Date is ambiguous, so it does not choose automatically. To use both classes together, write their fully qualified names, such as java.util.Date and java.sql.Date. An import can give the short name to only one of them; the other still needs its full name.
प्रश्न 8उत्तर + हल
किसी पैकेज की सुविधाओं (features) तक पहुँचने के लिए कौन-सा कीवर्ड प्रयोग किया जाता है?
Which keyword is used for accessing the features of a package?
  1. Apackage
  2. Bimport
  3. Cextends
  4. Dexport

सही उत्तर / Answer: (B)

हल / Solution
किसी दूसरे पैकेज की क्लासेज़ और इंटरफ़ेस को अपनी फ़ाइल में इस्तेमाल करने के लिए import कीवर्ड लगता है, जैसे import java.util.ArrayList; package कीवर्ड यह बताता है कि यह फ़ाइल ख़ुद किस पैकेज की है, वह दूसरे पैकेज तक नहीं पहुँचाता। extends inheritance में मूल क्लास बताने के लिए है। export साधारण Java का कीवर्ड नहीं है। module में exports शब्द आता है, पर वह पैकेज को बाहर देता है, इस्तेमाल नहीं करता।
To use the classes and interfaces of another package in a file, Java uses the import keyword, for example import java.util.ArrayList; The package keyword declares which package the current file belongs to; it does not give access to other packages. The extends keyword names the parent class in inheritance. Export is not a Java keyword; modules use exports, but that shares a package with others rather than using one.
प्रश्न 9उत्तर + हल
import java.util.*; का उद्देश्य क्या है?
What is the purpose of import java.util.*;?
  1. Aसभी क्लासेज़ इम्पोर्ट करनाImport all classes
  2. Bwildcard क्लासेज़ इम्पोर्ट करनाImport wildcard classes
  3. Cसब-पैकेज समेत इम्पोर्ट करनाImport with sub-packages
  4. Dमौजूदा पैकेज इम्पोर्ट करनाImport the current package

सही उत्तर / Answer: (A)

हल / Solution
import java.util.*; में * का मतलब है java.util पैकेज की सभी public क्लासेज़ और इंटरफ़ेस, जैसे ArrayList, HashMap और Scanner। ये सब छोटे नाम से इस्तेमाल हो सकती हैं। ध्यान दीजिए कि * सब-पैकेज को नहीं लाता। java.util.regex की Pattern क्लास के लिए अलग से import java.util.regex.*; लिखना पड़ता है। wildcard क्लास जैसी कोई चीज़ नहीं होती, * सिर्फ़ चिह्न है। मौजूदा पैकेज को import करने की ज़रूरत ही नहीं होती।
In import java.util.*; the star means all public classes and interfaces of the java.util package, such as ArrayList, HashMap and Scanner, so they can be used by short names. Note that the star does not include sub-packages; the Pattern class of java.util.regex still needs import java.util.regex.*; There is no such thing as a wildcard class, since * is only a symbol. The current package never needs to be imported.
प्रश्न 10उत्तर + हल
किसी प्रोग्राम में सुरक्षा से जुड़े मुद्दों को सँभालने के लिए इनमें से किस पैकेज का उपयोग किया जाता है?
Which of these packages is used for handling security related issues in a program?
  1. Ajava.security
  2. Bjava.lang.security
  3. Cjava.awt.image
  4. Djava.io.security

सही उत्तर / Answer: (A)

हल / Solution
Java में सुरक्षा से जुड़ी क्लासेज़ java.security पैकेज में रखी गई हैं। इसमें MessageDigest से hash बनाना, KeyPairGenerator से कुंजियाँ बनाना, Signature से डिजिटल हस्ताक्षर और Permission जैसी क्लासेज़ आती हैं। java.lang.security और java.io.security नाम के कोई पैकेज JDK में हैं ही नहीं। ये सिर्फ़ भ्रम पैदा करने के लिए लिखे गए हैं। java.awt.image छवियों को सँभालने के लिए है, सुरक्षा के लिए नहीं।
Java keeps its security classes in the java.security package. It includes MessageDigest for hashing, KeyPairGenerator for creating keys, Signature for digital signatures, and classes such as Permission. There are no packages named java.lang.security or java.io.security in the JDK; those names are only distractors. The java.awt.image package deals with images, not security. So the correct answer is java.security.
आगे के 12 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 12उत्तर app में
जावा में "import static" स्टेटमेंट का उपयोग करने का उद्देश्य क्या है?
What is the purpose of using "import static" statements in Java?
  1. Aकिसी पैकेज की सभी क्लासेज़ इम्पोर्ट करना।To import all classes from a package.
  2. Bसिर्फ़ static मेथड वाली क्लासेज़ इम्पोर्ट करना।To import classes with static methods only.
  3. Cकिसी क्लास के static सदस्य (members) इम्पोर्ट करना।To import static members of a class.
  4. Dreflection के लिए क्लासेज़ इम्पोर्ट करना।To import classes for reflection purposes.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 13उत्तर app में
क्या एक ही पैकेज की क्लासेज़ को एक-दूसरे का उपयोग करने के लिए इम्पोर्ट की आवश्यकता होती है?
Do classes in the same package need imports to use each other?
  1. Aनहीं, इम्पोर्ट की ज़रूरत नहींNo, imports not needed
  2. Bहाँ, सबके लिए ज़रूरी हैYes, mandatory for all
  3. Cअनुमति नहीं हैNot allowed
  4. Dसिर्फ़ अब्स्ट्रैक्ट क्लासेज़ के लिएOnly for abstract classes
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 16उत्तर app में
हमारे जावा प्रोग्राम में पैकेज के अंदर की क्लासेज़, इंटरफ़ेस या अब्स्ट्रैक्ट क्लासेज़ का उपयोग करने के बारे में एक सही कथन चुनें।
Choose a correct statement about using the classes, interfaces or abstract classes inside the packages in our Java program.
  1. Aआप पैकेज से इम्पोर्ट की गई क्लास को extend कर सकते हैं।You can extend the class imported from the package.
  2. Bआप पैकेज से इम्पोर्ट किए गए इंटरफ़ेस को implement कर सकते हैं।You can implement the interfaces imported from the package.
  3. Cआप पैकेज से इम्पोर्ट की गई अब्स्ट्रैक्ट क्लास को extend कर सकते हैं।You can extend the abstract classes imported from the package.
  4. Dउपरोक्त सभीAll the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में
जावा प्रोग्राम में डिक्लेयर या इम्पोर्ट करते समय सुपर-पैकेज और सब-पैकेज को अलग करने के लिए कौन-सा प्रतीक प्रयोग किया जाता है?
Which symbol is used to separate a super-package and a sub-package at the time of declaring or importing in a Java program?
  1. Aडॉलर ($)Dollar ($)
  2. Bपाउंड (#)Pound (#)
  3. Cपीरियड (.) या डॉटPeriod (.) or DOT
  4. Dऐरो (->)Arrow (->)
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
आप जावा में पैकेज डिक्लेरेशन स्टेटमेंट से पहले एक कमेंट डाल सकते हैं। सत्य या असत्य बताइए।
You can place a comment before the package declaration statement in Java. State TRUE or FALSE.
  1. Aसत्यTRUE
  2. Bअसत्यFALSE
  3. Cकुछ नहीं कहा जा सकताNothing can be said
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
जावा में पैकेज की सही डिक्लेरेशन और इम्पोर्टिंग चुनें।
Choose the correct declaration and importing of packages in Java.
  1. Apackage SOMEPACKAGE;

    import PACKAGE_N.*;
  2. Bimport PACKAGE_N.*;

    package SOMEPACKAGE;
  3. Cimport PACKAGE_M.*;

    package SOMEPACKAGE;

    import PACKAGE_N.*;
  4. Dउपरोक्त सभीAll the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 21उत्तर app में
किसी पैकेज को जावा क्लास या इंटरफ़ेस में इम्पोर्ट करने के लिए उपयोग होने वाला कीवर्ड ___ है।
The keyword used to import a package into a Java class or interface is ___.
  1. Aimport
  2. Bdownload
  3. Cuse
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
Import and Static Import के सभी 22 प्रश्न — उत्तर, हल और अभ्यास

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

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

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

Programmer Java के दूसरे topics

सभी topics