FliQi Education App Download
विषय-वार प्रश्न-बैंक

Java — प्रश्न-बैंक

369 जाँचे हुए प्रश्न · 10 topics

Topics

और: Exception Handling · Features of Java · Inheritance · Abstraction · Encapsulation · Compilation process of java · AWT · OOPs Concepts - Interface · Polymorphism (कम प्रश्न — app में)

किन परीक्षाओं में

नमूना प्रश्न

भाषा
प्रश्न 1उत्तर + हल OOPs Concept (Basic)
अलग-अलग ऑब्जेक्ट बनाने के लिए टेम्पलेट (साँचा) कौन-सा है?
Which one is a template for creating different objects?
  1. Aऐरे (Array)An Array
  2. Bक्लास (Class)A class
  3. Cइंटरफ़ेस (Interface)Interface
  4. Dमेथड (Method)Method

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

हल / Solution
class एक साँचे या नक़्शे की तरह है। इसमें लिखा रहता है कि object में कौन-से variables (data) और कौन-से methods (काम) होंगे। एक ही class से new लगाकर कई अलग-अलग object बनाए जा सकते हैं, हर एक का अपना data होता है। array सिर्फ़ एक जैसे मानों का समूह है। interface का object सीधे नहीं बनता, उसे कोई class implement करती है। method तो class के अंदर का एक काम है।
A class works like a template or blueprint. It states which variables (data) and which methods (behaviour) an object will have. Using new, many different objects can be created from one class, each with its own data. An array is only a group of values of the same type. An interface cannot be instantiated directly; a class has to implement it. A method is just one task inside a class.
प्रश्न 2उत्तर + हल History & Introduction of Java
Java भाषा को शुरू में ________ कहा जाता था।
Java language was initially called ________.
  1. ASumatra
  2. BJ++
  3. COak
  4. DPine

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

हल / Solution
Java भाषा को शुरू में Oak कहा जाता था। James Gosling के दफ़्तर के बाहर oak का पेड़ था, उसी पर यह नाम रखा गया। Oak नाम पर पहले से trademark था, इसलिए 1995 में नाम बदलकर Java किया गया। Sumatra इंडोनेशिया का एक द्वीप है, जो Java द्वीप का पड़ोसी है। J++ Microsoft की अलग भाषा थी। Pine भी Oak की तरह सिर्फ़ एक पेड़ का नाम है।
Java was initially called Oak. There was an oak tree outside James Gosling's office, and the name came from it. The name Oak was already a trademark, so in 1995 the language was renamed Java. Sumatra is an island in Indonesia, a neighbour of the island of Java. J++ was a separate language made by Microsoft. Pine, like Oak, is just the name of a tree.
प्रश्न 3उत्तर + हल String class and String class Constructor
निम्न Java code क्या छापेगा?
System.out.println("a,b,,".split(",").length);
What will the following Java code print?
System.out.println("a,b,,".split(",").length);
  1. A4
  2. B2
  3. C3
  4. D1

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

हल / Solution
एक argument वाले साधारण रूप में split() नतीजे के अंत में बनने वाले ख़ाली strings को हटा देता है। a,b,, पाठ टूटकर a, b और दो ख़ाली टुकड़े देता, पर अंत के दोनों ख़ाली टुकड़े फेंक दिए जाते हैं और केवल a तथा b का array बचता है, इसलिए लंबाई 2 छपेगी। पाठ के बीच पड़ने वाले ख़ाली टुकड़े हमेशा बने रहते हैं, केवल पीछे वाले हटते हैं।
With the usual one argument form, split() drops the empty strings that would stand at the end of the result. The text a,b,, would break into a, b and two empty pieces, but both trailing empty pieces are thrown away, leaving an array of just a and b, so the length printed is 2. Empty pieces falling in the middle of the text are always kept, only trailing ones go.
प्रश्न 4उत्तर + हल First Java Application
main thread के मरने पर JVM क्या करता है?
What does the JVM do when the main thread dies?
  1. Aprogram दोबारा शुरू करता हैIt restarts the program
  2. Bदूसरा thread बनाता हैIt creates another thread
  3. Cकुछ नहीं, चलता रहता हैNothing, it keeps running
  4. Dअपनी सभी internal process बंद करके shut down mode में चला जाता हैIt shuts all its internal processes and goes into shut down mode

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

हल / Solution
पाठ का अंतिम चरण — जब main thread, main() method के end point पर पहुँच जाता है तो वह destroyed यानी dead अवस्था में चला जाता है, और जब main thread dead अवस्था में होता है तो JVM अपनी सभी internal process बंद कर देता है और shut down mode में चला जाता है। यही किसी Java application के चलने का अंत है।
The text's final step — when the main thread reaches the end point of the main() method it goes into a destroyed, that is dead, state, and when the main thread is in the dead state the JVM shuts down all its internal processes and goes into shut down mode. That is the end of a Java application's run.
प्रश्न 5उत्तर + हल Literals of Java
byte और short के literal को स्पष्ट रूप से बताने का तरीक़ा Java में क्या है?
What is the way to explicitly specify byte and short literals in Java?
  1. Ab और s प्रत्यय सेWith the b and s suffixes
  2. Bकोई सीधा तरीक़ा नहीं — range में आने पर compiler ख़ुद मान लेता हैThere is no direct way — the compiler takes it so when the value is within range
  3. C0b और 0s उपसर्ग सेWith the 0b and 0s prefixes
  4. D(byte) और (short) लिखना अनिवार्य हैWriting (byte) and (short) is compulsory

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

हल / Solution
पाठ कहता है — byte और short literal को स्पष्ट रूप से बताने का कोई सीधा तरीक़ा नहीं है; यह अप्रत्यक्ष रूप से होता है। जब byte variable को integral literal दिया जाता है और मान उसकी range में आता है तो compiler उसे अपने आप byte literal मान लेता है — «byte b = 127;» ठीक, «byte b = 128;» पर «Cannot convert int to byte»。
The text says — there is no direct way to specify byte and short literals explicitly; it happens indirectly. When an integral literal is assigned to a byte variable and the value falls within its range, the compiler treats it as a byte literal on its own — 'byte b = 127;' is fine, while 'byte b = 128;' gives 'Cannot convert int to byte'.
प्रश्न 6उत्तर + हल Types of Variables in Java
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.
प्रश्न 7उत्तर + हल Data Type in Java
«char ch2=65536;» पर क्या होगा?
What happens with 'char ch2=65536;'?
  1. Aकोई error नहींNo error
  2. Bवह ऋणात्मक मान बन जाएगाIt becomes a negative value
  3. C65536 को 0 मान लिया जाएगा65536 is taken as 0
  4. Dcompile-time error — यह char की range से बाहर हैA compile-time error — it is outside char's range

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

हल / Solution
char का आकार 2 byte है और उसकी range 0 से 65535 तक है, इसलिए 65536 उससे एक ऊपर चला जाता है और पाठ के अनुसार «possible loss of precision» वाली compile-time error मिलती है। उसी के साथ «char ch1=97;» वैध है, क्योंकि 97 range के भीतर है और char को संख्या से भी भरा जा सकता है — वह Unicode का वही अक्षर उठा लेता है।
A char is 2 bytes and its range runs from 0 to 65535, so 65536 goes one past it and, per the text, gives the 'possible loss of precision' compile-time error. Alongside it 'char ch1=97;' is valid, because 97 lies within the range and a char may be filled from a number too — it picks up that very Unicode character.
प्रश्न 8उत्तर + हल OOPs Concepts - Constructors
क्या constructor exception फेंक सकता है?
Can a constructor throw an exception?
  1. Aनहीं, कभी नहींNo, never
  2. Bनहीं, सिर्फ़ private हो तोNo, only if it is private
  3. Cनहीं, सिर्फ़ default हो तोNo, only if it is default
  4. Dहाँ, फेंक सकता हैYes, it can

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

हल / Solution
हाँ। किताब के «constructor के बारे में क्या सत्य है» वाले प्रश्न में «constructor exception नहीं फेंक सकता» को ग़लत विकल्प के रूप में रखा गया है, यानी वह फेंक सकता है। जो बातें सचमुच वर्जित हैं वे अलग हैं — return type लिखना, return statement रखना, और final, static, abstract या synchronized जैसा non-access modifier लगाना।
Yes. In the book's question on what is true about a constructor, 'a constructor cannot throw an exception' is placed as the wrong option, meaning it can throw one. The things genuinely forbidden are different — writing a return type, keeping a return statement, and applying a non-access modifier such as final, static, abstract or synchronized.
प्रश्न 9उत्तर + हल Identifiers of Java
«int System=10;» के बाद उसी program में System को class के रूप में इस्तेमाल करना हो तो क्या करना होगा?
After 'int System=10;', what must be done to use System as a class later in the same program?
  1. ASystem को दोबारा declare करना होगाSystem must be declared again
  2. Bउसे class में नहीं बदला जा सकताIt cannot be turned back into a class
  3. Cउसका पूरी तरह योग्य नाम लिखना होगा — java.lang.SystemIts fully qualified name must be written — java.lang.System
  4. Dprogram को दो file में बाँटना होगाThe program must be split into two files

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

हल / Solution
पाठ कहता है कि System को int variable बना लेने पर उसे शेष program में उसी रूप में इस्तेमाल करना होगा, और यदि class के रूप में चाहिए तो उसकी पूर्णतः योग्यता लिखनी होगी। उदाहरण में «java.lang.System.out.println(System);» चलता है जबकि सीधा «System.out.println(System);» पर compilation error मिलती है। package के नाम के साथ class का नाम बताना ही Fully Qualified Name कहलाता है।
The text says that once System has been made an int variable it must be used in that role through the remaining program, and if it is needed as a class then its fully qualified form must be written. In the example 'java.lang.System.out.println(System);' works, while a plain 'System.out.println(System);' gives a compilation error. Naming a class together with its package is what is called a Fully Qualified Name.
प्रश्न 10उत्तर + हल Keywords of Java
Java में goto पर रोक क्यों है, और const की जगह क्या रखा गया है?
Why is goto banned in Java, and what was put in place of const?
  1. Agoto धीमा चलता था; const की जगह staticgoto ran slowly; static in place of const
  2. Bgoto का नाम बदल गया; const की जगह enumgoto was renamed; enum in place of const
  3. Cgoto अब भी चलता है; const हटा दिया गयाgoto still works; const was removed
  4. Dपुरानी भाषाओं में goto से कई समस्याएँ बनीं; const की जगह finalgoto created several problems in older languages; final in place of const

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

हल / Solution
पाठ की श्रेणी viii यही बताती है — «Usage of goto created several problems in old languages and hence goto keyword is banned in java», और const के बारे में «use of final instead of const»। दोनों unused keyword हैं: reserved तो हैं, पर इस्तेमाल करने पर compile time error मिलती है, सो उन्हें identifier भी नहीं बनाया जा सकता।
Category viii of the text states exactly this — 'usage of goto created several problems in old languages and hence the goto keyword is banned in java', and of const, 'use of final instead of const'. Both are unused keywords: they are reserved, yet using them gives a compile time error, so they cannot be made identifiers either.
Java का पूरा प्रश्न-बैंकहर topic के सारे प्रश्न, हल और अभ्यास — FliQi Question Bank app में