new MyClass() लिखते ही बिना पैरामीटर वाला कन्स्ट्रक्टर चलता है। उसके भीतर this(0) लिखा है, यानी वह उसी class के दूसरे कन्स्ट्रक्टर को शून्य देकर बुला देता है। वहाँ this.value = value चलने से फ़ील्ड में शून्य बैठ जाता है। इसलिए getValue शून्य ही लौटाएगी और आउटपुट शून्य आएगा। यह कोड पूरी तरह वैध है, इसलिए न कम्पाइलेशन त्रुटि आती है न रनटाइम त्रुटि, और एक कहीं से नहीं आता।
Writing new MyClass() runs the no-argument constructor. Inside it sits this(0), which hands control to the other constructor of the same class with zero as the argument. There this.value = value puts zero into the field. So getValue returns zero and the program prints 0. The code is perfectly legal, so neither a compilation error nor a runtime error appears, and the value 1 never enters the picture.
Java में keyboard से input पढ़ने के लिए Scanner object बनाने में कौन-सा constructor प्रयोग होता है?
Which of the following constructors is used to create a Scanner object to read input from the keyboard in Java?
AScanner(System.in)
BScanner(File file)
CScanner(Reader reader)
DScanner(String source)
सही उत्तर / Answer: (A)
हल / Solution
keyboard से input पढ़ने के लिए Scanner sc = new Scanner(System.in); लिखा जाता है। System.in एक InputStream है, जो standard input यानी keyboard से जुड़ा होता है। Scanner(File file) किसी file से पढ़ता है। Scanner(String source) दी गई String को ही पढ़कर tokens बनाता है। Reader वाला रूप किसी character stream से पढ़ता है, keyboard से सीधे नहीं। इसलिए keyboard input के लिए Scanner(System.in) सही है।
To read keyboard input we write Scanner sc = new Scanner(System.in);. System.in is an InputStream connected to standard input, which is normally the keyboard. Scanner(File file) reads from a file, and Scanner(String source) scans the given String itself and breaks it into tokens. The Reader form reads from a character stream that you supply, not directly from the keyboard. So Scanner(System.in) is the standard constructor for keyboard input, and option 1 is correct.
Aसंख्या को 2 से गुणा करनाMultiplying the number by 2
Bसंख्या को 2 से भाग देनाDividing the number by 2
Cसंख्या में से 2 घटानाSubtracting the number by 2
Dसंख्या में 2 जोड़नाAdding the number by 2
सही उत्तर / Answer: (B)
हल / Solution
बिट एक जगह दाएँ खिसकाने पर हर बिट का स्थानीय मान आधा हो जाता है। इसलिए एक बार दाएँ खिसकाना 2 से भाग देने के बराबर है, और n जगह खिसकाना 2 की n घात से भाग देने के बराबर। जैसे 20 को दो जगह खिसकाने पर 5 मिलता है। भाग में दशमलव नहीं बचता, नीचे की पूर्ण संख्या मिलती है। गुणा बाएँ शिफ्ट से होता है, इसलिए विकल्प 1 ग़लत है।
Moving the bits one place to the right halves the place value of every bit. So one right shift is the same as dividing by 2, and shifting n places is the same as dividing by 2 raised to n. For example, shifting 20 by two places gives 5. No fraction survives; you get the whole number below. Multiplying is what a left shift does, so option 1 is wrong, and options 3 and 4 are unrelated.
Java में किसी class को subclass बनने से रोकने के लिए कौन-सा keyword लगाया जाता है?
Which keyword is used to prevent a class from being subclassed in Java?
Aabstract
Bfinal
Cstatic
Dsealed
सही उत्तर / Answer: (B)
हल / Solution
final class को कोई extend नहीं कर सकता — इसीलिए String class final है, ताकि उसका बर्ताव बदला न जा सके। abstract तो उलटा है, वह class को extend कराने के लिए ही बनती है। static का काम nested class या member को class के स्तर पर बाँधना है, वंशानुक्रम रोकना नहीं। sealed सिर्फ़ चुनी हुई classes तक विरासत सीमित करता है, पूरी तरह रोकता नहीं। इसलिए उत्तर final है।
A final class cannot be extended by anyone, which is why the String class is final, so its behaviour stays safe. An abstract class is the opposite, since it exists to be extended. The static keyword ties a nested class or a member to the class level and never blocks inheritance. A sealed class only limits inheritance to chosen classes instead of stopping it. So final is the answer.
एक interface से दूसरे interface के बीच inheritance लागू करने के लिए निम्न में से किसका उपयोग किया जाता है?
Which of the following is used for implementing inheritance between interface to interface?
Ainherited
Busing
Cextends
Dimplements
सही उत्तर / Answer: (C)
हल / Solution
interface जब किसी दूसरे interface के तरीक़े लेता है तो वहाँ extends ही लगता है, जैसे interface B extends A। implements सिर्फ़ तब आता है जब कोई class किसी interface का काम पूरा करने का वादा करती है। ध्यान रखिए, एक interface कई interface को एक साथ extends कर सकता है, जो class के लिए संभव नहीं। inherited और using Java के कीवर्ड नहीं हैं, इसलिए पहले दो विकल्प तो शुरू में ही बाहर हो जाते हैं।
When one interface takes the methods of another interface, the word extends is used, as in interface B extends A. The keyword implements appears only when a class promises to supply the body of an interface. Note that a single interface may extend several interfaces at once, which a class cannot do. Neither inherited nor using is a Java keyword, so the first two options drop out straight away.
ओवरलोडिंग में एक ही नाम की कई method होती हैं और उनके पैरामीटर अलग-अलग होते हैं। कौन सी method चलेगी, यह compiler call में दिए गए तर्कों की संख्या और प्रकार देखकर पहले ही तय कर देता है। इसीलिए इसे compile time polymorphism या early binding कहते हैं। रन टाइम और एक्ज़ीक्यूशन टाइम एक ही बात है और वह overriding पर लागू होती है, ओवरलोडिंग पर नहीं। कोडिंग के समय तो सिर्फ़ प्रोग्राम लिखा जाता है, कोई फ़ैसला नहीं होता।
In overloading there are several methods with one name and different parameter lists. The compiler looks at the number and the types of the arguments and fixes the right method before the program runs. That is why overloading is called compile time polymorphism or early binding. Run time and execution time mean the same thing, and that applies to overriding, not to overloading. At coding time the programmer only writes the program, so no decision is taken there.
What is the relationship between a class and an object in Java?
Aobject किसी class का instance होता है।An object is an instance of a class.
Bclass किसी object की instance होती है।A class is an instance of an object.
Cclass और object एक ही चीज़ हैं।A class and an object are the same thing.
Dobject class से inherit करता है।An object inherits from a class.
सही उत्तर / Answer: (A)
हल / Solution
class एक साँचा है और object उस साँचे से बनी असली इकाई। इसीलिए कहा जाता है कि object अपनी class का instance है, और पहला विकल्प सही है। दूसरा विकल्प रिश्ते को उलटा कर देता है। तीसरा दोनों को एक ही चीज़ बता देता है, जबकि class लिखने के समय की परिभाषा है और object चलते समय की चीज़। चौथे विकल्प वाला inherit का रिश्ता दो class के बीच होता है, class और object के बीच नहीं।
A class is a mould and an object is the real unit made from it. That is why we say an object is an instance of its class, so option 1 is correct. Option 2 turns the relation upside down. Option 3 treats the two as one thing, though a class is a definition written in advance while an object exists at runtime. The inheritance of option 4 holds between two classes, not between a class and an object.
encapsulation की अवधारणा का उपयोग करने से डेटा की सुरक्षा कैसी रहती है?
Using the concept of encapsulation, security of the data is ___________
Aकुछ हद तक सुनिश्चितEnsured to some extent
Bपूरी तरह सुनिश्चितPurely ensured
Cसुनिश्चित नहींNot ensured
Dबहुत कमVery low
सही उत्तर / Answer: (A)
हल / Solution
encapsulation fields को private करके सीधी पहुँच रोक देता है, इसलिए सुरक्षा बढ़ती है। पर यह पूरी सुरक्षा नहीं है — reflection से private field तक पहुँचा जा सकता है, और लापरवाही से लिखा setter ख़ुद ही रास्ता खोल देता है। इसलिए सही बात यही है कि सुरक्षा कुछ हद तक मिलती है, और पहला विकल्प ठीक बैठता है। दूसरा विकल्प ज़्यादा दावा करता है, तीसरा और चौथा फ़ायदा ही नकार देते हैं।
Encapsulation makes the fields private and blocks direct access, so security does improve. Yet the protection is not complete: reflection can reach a private field, and a carelessly written setter opens a door by itself. So the honest answer is that security is ensured to some extent, which is option 1. Option 2 claims too much, while options 3 and 4 deny a benefit that clearly exists.
Java प्रोग्रामों को compile करने के लिए ...... को लिखा जाता है।
To compile Java programs, ...... is written.
A.java
B.javac
C.Cjava
D.jawa
सही उत्तर / Answer: (B)
हल / Solution
जावा का प्रोग्राम .java नाम वाली फ़ाइल में सहेजा जाता है, पर उसे compile करने के लिए javac चलाया जाता है। यह औज़ार JDK के साथ आता है और source code को bytecode में बदलकर .class फ़ाइल बना देता है। पहला विकल्प सिर्फ़ source फ़ाइल का नाम बताता है, compiler का नहीं। बाक़ी दो रूप .Cjava और .jawa जावा में होते ही नहीं, इसलिए वे ग़लत हैं।
A Java program is saved in a file with the .java extension, but to compile it you run javac, the compiler that comes with the JDK. It turns the source code into bytecode and stores it in a .class file. The first choice names the source file, not the compiler. The last two spellings, .Cjava and .jawa, do not exist in Java at all.
क्या जावा में किसी interface में constructor हो सकता है?
Can an interface contain a constructor in Java?
AहाँYes
BनहींNo
CशायदMaybe
Dइनमें से कोई नहींNone
सही उत्तर / Answer: (B)
हल / Solution
constructor का काम object बनने के समय उसे तैयार करना है। interface का object कभी बनता ही नहीं, इसलिए वहाँ constructor की ज़रूरत नहीं और जावा उसे रखने भी नहीं देता। लिखने पर compile के समय ही ग़लती मिल जाती है। इसलिए सही उत्तर नहीं है, यानी दूसरा विकल्प। पहला विकल्प हाँ कहता है, जो ग़लत है। यहाँ बीच का कोई रास्ता नहीं है, नियम साफ़ है, इसलिए तीसरा और चौथा विकल्प भी नहीं चलते।
A constructor exists to set up an object at the moment it is created. An interface is never instantiated, so it needs no constructor and Java does not allow one. If you write it, the error appears at compile time itself. That is why the answer is No, which is option 2. Option 1 says yes, which is wrong. There is no middle ground here, the rule is clear, so maybe and none do not work either.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
यदि कोई code में encapsulation की अवधारणा का उपयोग कर रहा है, तो निम्नलिखित में से कौन सी बात सही है?
Which among the following concept is correct if a user using the concept of encapsulation in a code?
Acode बदलना अतिरिक्त बोझ बन सकता हैThe modification of the code can be additional overhead
Bmember functions से data members का data type बदला जा सकता हैMember functions can be used for modifying the data type of data members
Cdata member का data type बदला ही नहीं जा सकताThe data type of data member cannot be modified.
Ddata member का data type बाक़ी code छेड़े बिना आसानी से बदला जा सकता हैThe data type of the data member can be easily modified without modifying any other code