Inheritance: 38 MCQs with answers
All 38 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 20 questions
Q1. Inheritance માં 'is-a' સંબંધનો અર્થ શું છે?
BeginnerShow answer & explanation
એક class બીજા class નો પ્રકાર છે
'is-a' સંબંધ દર્શાવે છે કે child class એ parent class નો એક પ્રકાર છે. ઉદાહરણ તરીકે, 'Dog' એ 'Animal' છે. આ Inheritance નો મૂળભૂત સિદ્ધાંત છે.
Q2. નીચેનામાંથી કયો Inheritance નો પ્રકાર નથી?
BeginnerShow answer & explanation
Double Inheritance
Inheritance ના મુખ્ય પ્રકારો Single, Multilevel, Hierarchical અને Multiple છે. 'Double Inheritance' એ કોઈ માન્ય પ્રકાર નથી.
Q3. Child class parent class ના કયા members ને વારસામાં મેળવી શકતો નથી?
BeginnerShow answer & explanation
Private members
Child class parent class ના private members ને વારસામાં મેળવી શકતો નથી. તે ફક્ત public અને protected members ને જ વારસામાં મેળવે છે.
Q4. નીચેનામાંથી કયો સંબંધ Inheritance માટે યોગ્ય છે?
BeginnerShow answer & explanation
Cat અને Animal
'Cat' અને 'Animal' વચ્ચે 'is-a' સંબંધ છે (Cat એ Animal છે). બાકીના વિકલ્પો 'has-a' સંબંધ દર્શાવે છે, જે composition માટે યોગ્ય છે.
Q5. Multilevel Inheritance માં કેટલા levels હોઈ શકે છે?
BeginnerShow answer & explanation
કોઈ મર્યાદા નથી, પરંતુ ઊંડી hierarchy ટાળવી જોઈએ
Multilevel Inheritance માં levels ની કોઈ નિશ્ચિત મર્યાદા નથી, પરંતુ ખૂબ ઊંડી inheritance hierarchies જટિલતા વધારે છે અને તેને ટાળવી જોઈએ.
Q6. Java ભાષા Multiple Inheritance ને કેવી રીતે સપોર્ટ કરે છે?
BeginnerShow answer & explanation
Interfaces નો ઉપયોગ કરીને
Java Multiple Inheritance ને સીધું સમર્થન આપતી નથી કારણ કે તે 'diamond problem' તરફ દોરી શકે છે. તેના બદલે, Java interfaces નો ઉપયોગ કરીને બહુવિધ વર્તણૂકો પ્રાપ્ત કરવાની મંજૂરી આપે છે.
Q7. Inheritance નો ઉપયોગ કરતી વખતે સૌથી મહત્વપૂર્ણ શું છે?
BeginnerShow answer & explanation
'is-a' સંબંધ હોવો જોઈએ
Inheritance નો ઉપયોગ કરતી વખતે સૌથી મહત્વપૂર્ણ બાબત એ છે કે બે classes વચ્ચે 'is-a' સંબંધ હોવો જોઈએ. ફક્ત code reusability માટે Inheritance નો ઉપયોગ કરવો યોગ્ય નથી.
Q8. નીચેનામાંથી કયું વિધાન Inheritance વિશે સાચું છે?
BeginnerShow answer & explanation
Inheritance polymorphism ને સમર્થન આપે છે
Inheritance polymorphism ને સમર્થન આપે છે, જ્યાં તમે parent class ના reference દ્વારા child class ના ઑબ્જેક્ટને સંભાળી શકો છો. બાકીના વિકલ્પો ખોટા છે: Inheritance હંમેશા code ને સરળ બનાવતું નથી, તેનો ઉપયોગ ઘણા ક્ષેત્રોમાં થાય છે, અને child class બધા members ને બદલી શકતો નથી.
Q9. જો 'Vehicle' parent class છે અને 'Car', 'Bike', 'Truck' child classes છે, તો આ કયા પ્રકારનો Inheritance છે?
BeginnerShow answer & explanation
Hierarchical Inheritance
આ Hierarchical Inheritance છે કારણ કે એક parent class ('Vehicle') ને બહુવિધ child classes ('Car', 'Bike', 'Truck') છે.
Q10. Inheritance નો ઉપયોગ કરીને તમે શું પ્રાપ્ત કરી શકો છો?
BeginnerShow answer & explanation
Code reusability અને polymorphism
Inheritance code reusability અને polymorphism બંને પ્રાપ્ત કરવામાં મદદ કરે છે. Code reusability દ્વારા તમારે code ફરીથી લખવાની જરૂર નથી, અને polymorphism દ્વારા તમે parent class ના reference દ્વારા child class ના ઑબ્જેક્ટને સંભાળી શકો છો.
Q11. ખૂબ ઊંડી inheritance hierarchy ની શું સમસ્યા છે?
BeginnerShow answer & explanation
તે code ને જટિલ અને સમજવામાં મુશ્કેલ બનાવે છે
ખૂબ ઊંડી inheritance hierarchy code ને જટિલ અને સમજવામાં મુશ્કેલ બનાવે છે. તેનાથી code ની જાળવણી કરવી મુશ્કેલ બને છે અને bugs શોધવામાં સમય લાગે છે. સારી પ્રેક્ટિસ એ છે કે hierarchy ને શક્ય તેટલી છીછરી (shallow) રાખવી.
Q12. Inheritance ફક્ત code reusability માટે ઉપયોગી છે.
BeginnerShow answer & explanation
False
Inheritance ફક્ત code reusability માટે જ નહીં, પરંતુ સંબંધોને મોડેલ કરવા, code ને સંગઠિત કરવા અને polymorphism ને સમર્થન આપવા માટે પણ ઉપયોગી છે.
Q13. Child class parent class ના private members ને વારસામાં મેળવી શકે છે.
BeginnerShow answer & explanation
False
Child class parent class ના private members ને વારસામાં મેળવી શકતો નથી. તે ફક્ત public અને protected members ને જ વારસામાં મેળવે છે.
Q14. Inheritance શું છે? સમજાવો.
BeginnerShow answer & explanation
—
આ મૂળભૂત વ્યાખ્યા છે.
Q15. Parent class અને Child class વચ્ચે શું સંબંધ છે?
BeginnerShow answer & explanation
—
આ સંબંધ 'is-a' તરીકે ઓળખાય છે.
Q16. Single Inheritance નું ઉદાહરણ આપો.
BeginnerShow answer & explanation
—
આ સૌથી સરળ પ્રકારનો Inheritance છે.
Q17. Multilevel Inheritance નું ઉદાહરણ આપો.
BeginnerShow answer & explanation
—
આમાં inheritance ની સાંકળ બને છે.
Q18. Hierarchical Inheritance નું ઉદાહરણ આપો.
BeginnerShow answer & explanation
—
એક માતા-પિતા, અનેક બાળકો.
Q19. Inheritance નો મુખ્ય ફાયદો શું છે?
BeginnerShow answer & explanation
—
આ Inheritance ના મુખ્ય ફાયદા છે.
Q20. Child class parent class ના કયા members ને વારસામાં મેળવી શકતો નથી?
BeginnerShow answer & explanation
—
આ members ફક્ત parent class માં જ ઉપલબ્ધ છે.
Building up · 11 questions
Q21. Multiple Inheritance શું છે? તેની મર્યાદા શું છે?
IntermediateShow answer & explanation
—
આ એક મહત્વપૂર્ણ ખ્યાલ છે.
Q22. Inheritance અને Composition વચ્ચે શું તફાવત છે?
IntermediateShow answer & explanation
—
આ બે અલગ અલગ પ્રકારના સંબંધો છે.
Q23. GUI Frameworks માં Inheritance નો ઉપયોગ કેવી રીતે થાય છે?
IntermediateShow answer & explanation
—
આનાથી GUI components ને એકસમાન રીતે સંભાળી શકાય છે.
Q24. Polymorphism સાથે Inheritance નો શું સંબંધ છે?
IntermediateShow answer & explanation
—
એક જ interface, અનેક વર્તણૂકો.
Q25. Game Development માં Inheritance નો ઉપયોગ કેવી રીતે થાય છે?
IntermediateShow answer & explanation
—
આનાથી દુશ્મનોને એકસમાન રીતે સંભાળી શકાય છે.
Q26. Data Structures માં Inheritance નો ઉપયોગ કેવી રીતે થાય છે?
IntermediateShow answer & explanation
—
આનાથી data structures ને એકસમાન રીતે સંભાળી શકાય છે.
Q27. નીચેનામાંથી કયો સંબંધ Inheritance (વારસા) માટે સૌથી યોગ્ય છે?
IntermediateShow answer & explanation
Dog (કૂતરો) અને Animal (પ્રાણી) વચ્ચેનો સંબંધ
Inheritance માટે 'is-a' (છે) સંબંધ જરૂરી છે. 'Dog' એ 'Animal' છે, તેથી આ 'is-a' સંબંધ દર્શાવે છે. બાકીના વિકલ્પો 'has-a' (ધરાવે છે) સંબંધ દર્શાવે છે, જે Composition માટે યોગ્ય છે, Inheritance માટે નહીં.
Q28. જો Parent Class 'Vehicle' (વાહન) માં 'startEngine()' અને 'stopEngine()' methods છે, અને Child Class 'Car' (કાર) માં 'openTrunk()' method ઉમેરવામાં આવે છે, તો 'Car' class ના ઑબ્જેક્ટ પર નીચેનામાંથી કઈ method કૉલ કરી શકાય છે?
IntermediateShow answer & explanation
'startEngine()', 'stopEngine()' અને 'openTrunk()' ત્રણેય
Child class (Car) parent class (Vehicle) ના બધા public members (અહીં 'startEngine()' અને 'stopEngine()') ને વારસામાં મેળવે છે, અને પોતાના વિશિષ્ટ members ('openTrunk()') પણ ધરાવે છે. તેથી Car class ના ઑબ્જેક્ટ પર ત્રણેય methods કૉલ કરી શકાય છે.
Q29. Multilevel Inheritance માં, જો 'Vehicle' → 'Car' → 'SportsCar' એક hierarchy છે, તો 'SportsCar' class ના ઑબ્જેક્ટને કયા class(es) ના members મળે છે?
IntermediateShow answer & explanation
'SportsCar', 'Car' અને 'Vehicle' ત્રણેય class ના members
Multilevel Inheritance માં, દરેક child class તેના તમામ પૂર્વજો (ancestors) પાસેથી members વારસામાં મેળવે છે. અહીં 'SportsCar' એ 'Car' નું child છે અને 'Car' એ 'Vehicle' નું child છે, તેથી 'SportsCar' ને ત્રણેય class ના members મળે છે.
Q30. નીચેનામાંથી કયું વિધાન Inheritance (વારસા) ના ઉપયોગ વિશે સાચું છે?
IntermediateShow answer & explanation
Inheritance નો ખરો હેતુ classes વચ્ચે 'is-a' સંબંધને મોડેલ કરવાનો છે.
Inheritance નો મુખ્ય હેતુ 'is-a' સંબંધ ધરાવતી classes વચ્ચેના સંબંધને મોડેલ કરવાનો છે. Code reusability એ તેનો એક ફાયદો છે, પરંતુ તે એકમાત્ર હેતુ નથી. ખૂબ ઊંડી inheritance hierarchies code ને જટિલ બનાવી શકે છે.
Q31. જો 'Vehicle' parent class છે અને 'Car', 'Bike', 'Truck' એ બધા 'Vehicle' ના child classes છે, તો આ કયા પ્રકારનો Inheritance છે?
IntermediateShow answer & explanation
Hierarchical Inheritance
Hierarchical Inheritance માં, એક parent class ને બહુવિધ child classes હોય છે. અહીં 'Vehicle' parent છે અને 'Car', 'Bike', 'Truck' એ બધા તેના child classes છે, તેથી આ Hierarchical Inheritance નું ઉદાહરણ છે.
Topper level · 7 questions
Q32. Inheritance નો ઉપયોગ કરતી વખતે શું ધ્યાન રાખવું જોઈએ?
AdvancedShow answer & explanation
—
આ બે સામાન્ય ભૂલો છે.
Q33. Inheritance નો ખરો હેતુ શું છે?
AdvancedShow answer & explanation
—
આ એક સામાન્ય ગેરસમજણ છે.
Q34. ધારો કે તમારી પાસે નીચેનો Java code છે: ```java class Animal { protected String sound = "Generic sound"; public void makeSound() { System.out.println(sound); } } class Dog extends Animal { private String sound = "Bark"; @Override public void makeSound() { System.out.println(sound); } } public class Test { public static void main(String[] args) { Animal a = new Dog(); a.makeSound(); } } ``` આ code નું આઉટપુટ શું હશે?
AdvancedShow answer & explanation
Bark
અહીં `Dog` class માં `sound` field ને **hide** કરવામાં આવ્યો છે (field hiding), પરંતુ `makeSound()` method ને **override** કરવામાં આવ્યો છે. Polymorphism ના કારણે, runtime પર `Dog` નો `makeSound()` call થાય છે, જે `Dog` ના `sound` field નો ઉપયોગ કરે છે. Field hiding polymorphism ને અનુસરતું નથી, પરંતુ method overriding…
Q35. નીચેના Java code ને ધ્યાનમાં લો: ```java class A { int x = 10; void display() { System.out.println("Class A: " + x); } } class B extends A { int x = 20; void display() { System.out.println("Class B: " + x); } } class C extends B { int x = 30; void display() { System.out.println("Class C: " + x); } } public class Main { public static void main(String[] args) { A obj = new C(); System.out.println(obj.x); obj.display(); } } ``` આ code નું આઉટપુટ શું હશે?
AdvancedShow answer & explanation
10\nClass C: 30
Fields (variables) માટે, Java compile-time type (અહીં `A`) ના આધારે value નક્કી કરે છે, તેથી `obj.x` એ `A` ના `x` (10) ને access કરે છે. પરંતુ methods માટે, runtime type (અહીં `C`) ના આધારે overriding method call થાય છે, તેથી `obj.display()` એ `C` ના `display()` ને call કરે છે, જે `C` ના `x` (30) ને print કરે છે. આથી પ…
Q36. ધારો કે તમારી પાસે નીચેનો Java code છે: ```java class Parent { public static void greet() { System.out.println("Hello from Parent"); } public void instanceMethod() { System.out.println("Parent instance"); } } class Child extends Parent { public static void greet() { System.out.println("Hello from Child"); } @Override public void instanceMethod() { System.out.println("Child instance"); } } public class Test { public static void main(String[] args) { Parent p = new Child(); p.greet(); p.instanceMethod(); } } ``` આ code નું આઉટપુટ શું હશે?
AdvancedShow answer & explanation
Hello from Parent\nChild instance
Static methods **cannot be overridden**; they are **hidden**. જ્યારે `p.greet()` call થાય છે, ત્યારે compile-time type (`Parent`) ના આધારે `Parent` નો `greet()` call થાય છે. પરંતુ `instanceMethod()` એ instance method છે અને તે override થાય છે, તેથી runtime type (`Child`) ના આધારે `Child` નો `instanceMethod()` call થાય…
Q37. નીચેના Java code ને ધ્યાનમાં લો: ```java class Base { private int value = 10; public int getValue() { return value; } } class Derived extends Base { private int value = 20; public int getValue() { return value; } public int getBaseValue() { return super.getValue(); } } public class Test { public static void main(String[] args) { Derived d = new Derived(); System.out.println(d.getValue()); System.out.println(d.getBaseValue()); } } ``` આ code નું આઉટપુટ શું હશે?
AdvancedShow answer & explanation
20\n10
`Derived` class માં `getValue()` method override થાય છે અને તે `Derived` ના `value` (20) ને return કરે છે. `getBaseValue()` method માં `super.getValue()` call થાય છે, જે `Base` ના `getValue()` ને call કરે છે, જે `Base` ના private field `value` (10) ને return કરે છે. Private fields directly accessible નથી, પરંતુ public…
Q38. ધારો કે તમારી પાસે નીચેનો Java code છે: ```java interface A { default void show() { System.out.println("A"); } } interface B { default void show() { System.out.println("B"); } } class C implements A, B { public void show() { A.super.show(); B.super.show(); System.out.println("C"); } } public class Test { public static void main(String[] args) { C obj = new C(); obj.show(); } } ``` આ code નું આઉટપુટ શું હશે?
AdvancedShow answer & explanation
A\nB\nC
Java માં multiple inheritance of type (interfaces) ને સપોર્ટ કરે છે. જ્યારે બે interfaces માં સમાન default method હોય, ત્યારે implementing class એ method ને override કરવો જ જોઈએ. અહીં `C` class માં `show()` method માં `A.super.show()` અને `B.super.show()` ને call કરવામાં આવ્યા છે, જે ક્રમશઃ "A" અને "B" print કરે છે, અન…
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages