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

OOPs Concepts - Inheritance — प्रश्न और उत्तर

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

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

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

भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित में से कौन वंशानुक्रम (inheritance) का सबसे अच्छा वर्णन करता है?
Which among the following best describes Inheritance?
  1. Aआधार क्लास के डेटा और function को व्युत्पन्न भाग (derived segment) में इस्तेमाल करनाUsing the data and functions into derived segment
  2. Bकिसी programming language में पहले से बने function इस्तेमाल करनाUsing already defined functions in a programming language
  3. Cएक बार लिखे हुए कोड को इस्तेमाल करनाUsing the code already written once
  4. Dपहले लिखे हुए कोड की नक़ल कर लेनाCopying the code already written

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

हल / Solution
वंशानुक्रम (inheritance) का मतलब है आधार क्लास (base class) के डेटा और function को व्युत्पन्न क्लास में आगे बढ़ाकर इस्तेमाल करना — इसलिए पहला विकल्प सबसे सटीक है। पहले से बने function बुलाना तो library का साधारण उपयोग है, उसमें क्लास के बीच कोई नया संबंध नहीं बनता। एक बार लिखा कोड इस्तेमाल करना बहुत ढीली बात है, वह हर method बुलाने पर भी लागू होगी। नक़ल करना तो उलटा है, क्योंकि वहाँ कोड दो जगह हो जाता है।
Inheritance means the data and functions of a base class are carried into a derived class and used there, so the first option describes it best. Calling functions that already exist is just ordinary library use and creates no new relationship between classes. Saying you use code written once is far too loose, since that is true of any method call. Copying code is the opposite, because the code then lives in two places.
प्रश्न 2उत्तर + हल
आधार क्लास (base class) के किस प्रकार के सदस्य उसकी व्युत्पन्न क्लास (derived class) में पहुँच से बाहर रहते हैं?
Which type of members can't be accessed in the derived classes of a base class?
  1. Aसभी तक पहुँचा जा सकता हैAll can be accessed
  2. BprotectedProtected
  3. CprivatePrivate
  4. DpublicPublic

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

हल / Solution
private सदस्य सिर्फ़ उसी क्लास के भीतर दिखते हैं जिसमें वे लिखे गए हैं। उप-क्लास (subclass) उन्हें सीधे छू नहीं सकती, इसलिए तीसरा विकल्प सही है। वे वस्तु में मौजूद तो रहते हैं, पर उन तक पहुँचने का रास्ता आधार क्लास के public या protected method ही देते हैं। protected सदस्य व्युत्पन्न क्लास में मिलते हैं, यही उनका मक़सद है, और public सदस्य हर जगह मिलते हैं। इसलिए पहला विकल्प भी ग़लत है।
A private member is visible only inside the class where it is written. A subclass cannot touch it directly, so the third option is correct. The member still exists inside the object; the only way to reach it is through a public or protected method of the base class. protected members are reachable in a derived class, which is exactly their purpose, and public members are reachable everywhere, so the first option is wrong.
प्रश्न 3उत्तर + हल
OOP की कौन सी विशेषता नेस्टेड क्लास (nested class) के उपयोग को घटाती है?
Which feature of OOP reduces the use of nested classes?
  1. Aवंशानुक्रम (Inheritance)Inheritance
  2. Bबाइंडिंग (Binding)Binding
  3. Cएब्स्ट्रैक्शन (Abstraction)Abstraction
  4. Dएनकैप्सुलेशन (Encapsulation)Encapsulation

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

हल / Solution
वंशानुक्रम (inheritance) में साझा कोड आधार क्लास (base class) में रख दिया जाता है और नई क्लास उसे बढ़ाकर काम चला लेती है। इसलिए एक क्लास के भीतर दूसरी क्लास, यानी नेस्टेड क्लास लिखने की ज़रूरत घट जाती है। बाइंडिंग (binding) तो method के बुलावे को उसके कोड से जोड़ने की प्रक्रिया है। एब्स्ट्रैक्शन (abstraction) ब्योरा छिपाता है और एनकैप्सुलेशन (encapsulation) डेटा को बाँधता है; दोनों का क्लास के ढाँचे से यह नाता नहीं है।
With inheritance the shared code is kept in a base class and a new class simply extends it, so there is far less need to write one class inside another as a nested class. Binding is only the act of linking a method call to the code that will run. Abstraction hides detail and encapsulation wraps data together with its methods; neither of them removes the need for nesting.
प्रश्न 4उत्तर + हल
OOP की कौन सी विशेषता कोड के पुनः प्रयोग (code reusability) को दर्शाती है?
Which feature of OOP indicates code reusability?
  1. Aएब्स्ट्रैक्शन (Abstraction)Abstraction
  2. Bपॉलीमॉर्फिज़्म (Polymorphism)Polymorphism
  3. Cएनकैप्सुलेशन (Encapsulation)Encapsulation
  4. Dवंशानुक्रम (Inheritance)Inheritance

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

हल / Solution
वंशानुक्रम (inheritance) में एक क्लास दूसरी क्लास के गुण और method अपने आप पा जाती है, इसलिए वही कोड दोबारा लिखना नहीं पड़ता — कोड का पुनः प्रयोग यहीं से आता है। एब्स्ट्रैक्शन (abstraction) सिर्फ़ ज़रूरी बात दिखाकर ब्योरा छिपाता है। पॉलीमॉर्फिज़्म (polymorphism) एक ही नाम को कई रूपों में चलाता है। एनकैप्सुलेशन (encapsulation) डेटा और method को एक इकाई में बाँधकर सुरक्षित रखता है। इसलिए चौथा विकल्प सही है।
In inheritance a class automatically receives the fields and methods of another class, so the same code need not be written again, and that is where reuse comes from. Abstraction only shows what matters and hides the details. Polymorphism lets one name behave in several forms. Encapsulation binds data and methods into one unit and keeps the data safe. So the fourth option is the right answer.
प्रश्न 5उत्तर + हल
किसी class को दूसरी class द्वारा inherit होने से रोकने के लिए किस कीवर्ड का उपयोग किया जाता है?
Which keyword is used to prevent a class from being inherited by other classes?
  1. Ainherit
  2. Bsealed
  3. Cprevent
  4. Dfinal

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

हल / Solution
class के आगे final लिख दीजिए, फिर कोई उसे extends नहीं कर सकता — compiler वहीं रोक देता है। String, Integer और बाक़ी wrapper class इसी तरह final रखी गई हैं ताकि उनका व्यवहार सुरक्षित रहे। sealed जावा में बहुत बाद में आया और वह रोकता नहीं, बल्कि तय करता है कि कौन-कौन extends कर सकता है। inherit तथा prevent जावा के कीवर्ड हैं ही नहीं।
Write final in front of a class and nobody can extend it; the compiler stops any such attempt. String, Integer and the other wrapper classes are kept final in just this way so that their behaviour stays safe. The word sealed arrived in Java much later and does not block inheritance at all; it names the classes that are allowed to extend. Neither inherit nor prevent is a Java keyword.
प्रश्न 6उत्तर + हल
class और interface के बारे में सही कथन है/हैं
Correct statement about a class and interface is/are
  1. Aएक interface कई interface को extends कर सकता हैAn interface can extend multiple interfaces
  2. Bएक class कई interface को implements कर सकती हैA class can implement multiple interfaces
  3. Cजावा interface की मदद से multiple inheritance का समर्थन करती हैJava supports multiple inheritance using interfaces
  4. Dउपरोक्त सभीAll of the above

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

हल / Solution
तीनों कथन सही हैं, इसलिए उत्तर उपरोक्त सभी है। एक interface कई interface को एक साथ extends कर सकता है, जो class के लिए संभव नहीं। एक class भी कई interface को एक साथ implements कर सकती है। इन्हीं दो छूटों के बल पर जावा में multiple inheritance का काम interface से निकल आता है, जबकि class से class पर वह रोक बनी रहती है। इसीलिए कोई एक विकल्प चुनना अधूरा होगा।
All three statements are true, so the answer is all of the above. One interface may extend several interfaces at once, which a class cannot do. A class may also implement several interfaces at the same time. These two allowances are exactly how Java obtains the effect of multiple inheritance through interfaces, while the bar on class to class inheritance stays in place. Choosing any single option would therefore be incomplete.
प्रश्न 7उत्तर + हल
जावा में extends और implements में क्या अंतर है?
What is the difference between "extends" and "implements" in Java?
  1. Aदोनों class की inheritance के लिए काम आते हैंBoth are used for class inheritance
  2. Bextends class की inheritance के लिए है, जबकि implements interface लागू करने के लिए है"Extends" is used for class inheritance, while "implements" is used for interface implementation
  3. Cदोनों interface लागू करने के लिए काम आते हैंBoth are used for interface implementation
  4. Dimplements class की inheritance के लिए है, जबकि extends interface लागू करने के लिए है"Implements" is used for class inheritance, while "extends" is used for interface implementation

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

हल / Solution
class को class से जोड़ने पर extends लगता है, और class जब किसी interface का काम पूरा करने का वादा करती है तब implements। इसलिए दूसरा विकल्प सही है। चौथे विकल्प में दोनों की भूमिकाएँ आपस में बदल दी गई हैं, इसलिए वह ग़लत है। पहला और तीसरा दोनों को एक ही काम का बता रहे हैं, जो सही नहीं। ध्यान रखिए, interface से interface पर फिर extends ही चलता है।
Joining a class to a class uses extends, while a class that promises to complete the work of an interface uses implements. That makes the second option correct. The fourth option swaps the two roles, so it is wrong. The first and third options claim that both words do the same job, which is not true. Note also that going from one interface to another interface uses extends again.
प्रश्न 8उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?

class First

{

    static void staticMethod()

    {

        System.out.println("Static Method");

    }

}



public class MainClass

{

    public static void main(String[] args)

    {

        First first = null;



        first.staticMethod();

    }

}
What will be the output of the following program?

class First

{

    static void staticMethod()

    {

        System.out.println("Static Method");

    }

}



public class MainClass

{

    public static void main(String[] args)

    {

        First first = null;



        first.staticMethod();

    }

}
  1. AStatic Method
  2. BNullPointerException फेंकेगाThrows a NullPointerException
  3. Cकंपाइल टाइम एररCompile-time error
  4. Dरनटाइम एररRuntime error

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

हल / Solution
staticMethod पूरी class की है, किसी object की नहीं। इसलिए reference का मान null होने पर भी उसे चलाने में कोई अड़चन नहीं आती। compiler उस पंक्ति को चुपचाप बदल देता है और कॉल class के नाम से लगती है, यानी object की ज़रूरत पड़ती ही नहीं। इसी वजह से आउटपुट में वही पंक्ति छपती है जो method के भीतर लिखी है। null से गड़बड़ तब होती है जब instance method बुलाई जाए।
The method staticMethod belongs to the whole class, not to any object. So even though the reference holds null, running it causes no trouble at all. The compiler quietly rewrites that line and makes the call through the class name, which means no object is needed. That is why the output is simply the line written inside the method. A null reference fails only when an instance method is called on it.
प्रश्न 9उत्तर + हल
निम्नलिखित जावा प्रोग्राम का आउटपुट क्या है?

class Grandparent {

    public void print() {

        System.out.println("Grandparent's Print()");

    }

}



class Parent extends Grandparent { }



class Child extends Parent { }



public class Main {

    public static void main(String[] args) {

        Child child = new Child();

        child.print();

    }

}
What is the output of the following Java program?

class Grandparent {

    public void print() {

        System.out.println("Grandparent's Print()");

    }

}



class Parent extends Grandparent { }



class Child extends Parent { }



public class Main {

    public static void main(String[] args) {

        Child child = new Child();

        child.print();

    }

}
  1. A"Child's Print()"
  2. B"Parent's Print()"
  3. C"Grandparent's Print()"
  4. Dकंपाइलेशन एररCompilation error

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

हल / Solution
यह multilevel inheritance है — Grandparent से Parent, फिर Parent से Child। Parent और Child दोनों ख़ाली हैं, किसी ने print को दोबारा नहीं लिखा। इसलिए child.print() बुलाते ही JVM ऊपर की ओर खोजता है और Grandparent वाली print चला देता है। छपने वाली पंक्ति वही है जो उस method के भीतर लिखी है। override न होने से Parent या Child के नाम कहीं नहीं छपते, और कोड पूरी तरह सही है इसलिए compile भी हो जाता है।
This is multilevel inheritance: Grandparent to Parent and then Parent to Child. Both Parent and Child are empty bodies, and neither rewrites print. So when child.print() is called, the JVM searches upward and runs the version found in Grandparent. The line that appears is exactly the one written inside that method. Since nothing is overridden, the names Parent or Child are never printed, and the code is valid so it compiles.
प्रश्न 10उत्तर + हल
क्या जावा में multiple inheritance पाने के लिए interface का उपयोग किया जा सकता है?
Can interfaces be used to achieve multiple inheritance in Java?
  1. AहाँYes
  2. BनहींNo
  3. Cकुछ कहा नहीं जा सकताNothing can be said
  4. Dइनमें से कोई नहींNone of these

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

हल / Solution
एक class कई interface एक साथ implements कर सकती है, इसलिए multiple inheritance का काम interface से निकल आता है। class से class वाला रास्ता बंद है, पर यह खुला रखा गया — वजह यह कि interface में सिर्फ़ method का ढाँचा होता है, शरीर class ख़ुद लिखती है। इसलिए दो जगह से एक ही नाम आने पर भी उलझन नहीं होती और diamond problem खड़ी नहीं होती।
A class may implement several interfaces at the same time, so the effect of multiple inheritance is obtained through interfaces. The class to class route is closed, but this one is deliberately left open. The reason is that an interface normally carries only the shape of a method, while the class supplies the body itself. Even if the same name arrives from two sides there is no confusion, so no diamond problem arises.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 11उत्तर app में
जावा में multilevel inheritance किसे कहते हैं?
What is multilevel inheritance in Java?
  1. Aएक class दो या दो से अधिक class को extends करेA class extends two or more classes
  2. Bदो या दो से अधिक class एक ही class को extends करेंTwo or more classes extend the same class
  3. Cएक class ऐसी class को extends करे जो ख़ुद किसी और class को extends करती हैA class extends another class which also extends another class
  4. Dउपरोक्त सभीAll of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 12उत्तर app में
क्या कोई sub class अपनी super class के private सदस्यों को विरासत में पा सकती है?
Can a subclass inherit private members of its superclass?
  1. AहाँYes
  2. BनहींNo
  3. Cकुछ कहा नहीं जा सकताNothing can be said
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 13उत्तर app में
जावा में 'super' कीवर्ड का उद्देश्य क्या है?
What is the purpose of the 'super' keyword in Java?
  1. Aparent class का constructor बुलानाTo call the constructor of the parent class
  2. Bchild class की method बुलानाTo call a method of the child class
  3. Cclass का नया instance बनानाTo create a new instance of a class
  4. Dstatic method परिभाषित करनाTo define a static method
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
क्या हम जावा में class से class वाली multiple inheritance कर सकते हैं?
Can we perform multiple inheritance between classes in Java?
  1. AहाँYes
  2. BनहींNo
  3. Cकुछ कहा नहीं जा सकताNothing can be said
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 16उत्तर app में
जावा की inheritance में sub class किसे कहते हैं?
What is a subclass in Java inheritance?
  1. Aउस class को जो किसी दूसरी class से गुण पाती हैThe class that inherits from another class
  2. Bउस class को जिससे गुण लिए जाते हैंThe class that is inherited from
  3. Cशृंखला की सबसे अंतिम class कोThe final class in the inheritance chain
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में
क्या जावा में कोई class अपनी super class से constructor विरासत में पा सकती है?
Can a class inherit constructors from its superclass in Java?
  1. AहाँYes
  2. BनहींNo
  3. Cकुछ कहा नहीं जा सकताNothing can be said
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
जावा प्रोग्रामिंग में Inheritance क्या है?
What is Inheritance in Java programming?
  1. Aयह वह प्रक्रिया है जिसमें एक class दूसरी class के field और method पा लेती हैIt's a process where one class acquires the properties (fields) and behaviors (methods) of another class
  2. Bयह main() method की मदद से नई class बनाने की प्रक्रिया हैIt's a process of creating a new class using the main() method
  3. Cयह जावा में object बनाने की तकनीक हैIt's a technique to create objects in Java
  4. Dयह package आयात करने के लिए जावा का ख़ास शब्द हैIt's a Java-specific term for importing packages
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 20उत्तर app में
sub class B द्वारा super class A के उस constructor को कॉल करने का सही तरीक़ा कौन सा है जिसमें कोई parameter नहीं है?
Which of these is the correct way of calling a constructor having no parameters, of superclass A by subclass B?
  1. Asuper(void);
  2. Bsuperclass.();
  3. Csuper.A();
  4. Dsuper();
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 21उत्तर app में
इनमें से कौन सा कथन ग़लत है?
Which of these is a false statement?
  1. Afinal class को inherit नहीं किया जा सकताA final class cannot be inherited
  2. Bfinal method को inherit किया जा सकता हैA final method can be inherited
  3. Cfinal method को override किया जा सकता हैA final method can be overridden
  4. Dclass के final variable का मान बदला नहीं जा सकताA final variable of a class cannot be changed
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 22उत्तर app में
जावा की multi-level inheritance में सबसे नीचे वाली sub class किसके सदस्य और गुण पाती है?
In multi-level inheritance in Java, the last subclass inherits the methods and properties of ____.
  1. Aसिर्फ़ ठीक ऊपर वाली एक super class केOnly one immediate superclass
  2. Bऊपर की कुछ class केA few classes above it
  3. Cऊपर की सभी class केAll classes above it
  4. Dकिसी के नहींNone
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 23उत्तर app में
जावा भाषा class से class के बीच ___ प्रकार की inheritance का समर्थन करती है।
Java language supports ___ type of inheritance between classes.
  1. AMultiple Inheritance
  2. BMulti-Level Inheritance
  3. CA और B दोनोंBoth A and B
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 24उत्तर app में
जावा में sub class क्या होती है?
What is a subclass in Java?
  1. Aजो class किसी दूसरी class के भीतर घोषित होA subclass is a class declared inside a class
  2. Bजो class किसी दूसरी class को extends करती हैA subclass is a class that extends another class
  3. Cउपरोक्त दोनोंBoth of the above
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 25उत्तर app में
जिस class को inherit या sub class किया जा रहा है, उसे ___ कहा जाता है।
The class that is being inherited or subclassed is called ___.
  1. Aसबक्लासSubclass
  2. Bसुपरक्लासSuperclass
  3. CA और B दोनोंBoth A and B
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 26उत्तर app में
Inheritance का अर्थ है
Inheritance means
  1. Asuper class, sub class को extends करती हैSuper class extends sub class
  2. Bsub class, super class को extends करती हैSub class extends super class
  3. Csub class, super class का object बनाती हैSub class creates object of super class
  4. Dउपरोक्त सभीAll of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 27उत्तर app में
निम्नलिखित जावा प्रोग्राम का आउटपुट क्या होगा?

class A

{

int i;

int j;

A()

{

i = 1;

j = 2;

}

}

class Output

{

public static void main(String args[])

{

A obj1 = new A();

A obj2 = new A();

System.out.print(obj1.equals(obj2));

}

}
What will be the output of the following Java program?

class A

{

int i;

int j;

A()

{

i = 1;

j = 2;

}

}

class Output

{

public static void main(String args[])

{

A obj1 = new A();

A obj2 = new A();

System.out.print(obj1.equals(obj2));

}

}
  1. Afalse
  2. Btrue
  3. C1
  4. Dकंपाइलेशन एररCompilation Error
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 28उत्तर app में
निम्नलिखित जावा प्रोग्राम का आउटपुट क्या होगा?

abstract class A

{

int i;

abstract void display();

}

class B extends A

{

int j;

void display()

{

System.out.println(j);

}

}

class Abstract_demo

{

public static void main(String args[])

{

B obj = new B();

obj.j=2;

obj.display();

}

}
What will be the output of the following Java program?

abstract class A

{

int i;

abstract void display();

}

class B extends A

{

int j;

void display()

{

System.out.println(j);

}

}

class Abstract_demo

{

public static void main(String args[])

{

B obj = new B();

obj.j=2;

obj.display();

}

}
  1. A0
  2. B2
  3. Cरनटाइम एररRuntime Error
  4. Dकंपाइलेशन एररCompilation Error
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 30उत्तर app में
यदि कोई class दो class को extends करे और दोनों में एक ही नाम तथा signature वाली method हो तो क्या होगा? मान लीजिए कि वह class उस method को ख़ुद लागू नहीं कर रही है।
What would be the result if a class extends two classes and both have a method with the same name and signature? Assume that the class is not implementing that method.
  1. Aरनटाइम एररRuntime error
  2. Bकंपाइल टाइम एररCompile time error
  3. Cकोड सफलतापूर्वक चल जाएगाCode runs successfully
  4. Dपहले वाली method चल जाएगीFirst called method is executed successfully
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
OOPs Concepts - Inheritance के सभी 48 प्रश्न — उत्तर, हल और अभ्यास

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

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

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

Programmer Java के दूसरे topics

सभी topics