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' સંબંધનો અર્થ શું છે?

Beginner
A એક class બીજા class નો ઉપયોગ કરે છે B એક class બીજા class નો ભાગ છે C એક class બીજા class ને બનાવે છે D એક class બીજા class નો પ્રકાર છે
Show answer & explanation

એક class બીજા class નો પ્રકાર છે

'is-a' સંબંધ દર્શાવે છે કે child class એ parent class નો એક પ્રકાર છે. ઉદાહરણ તરીકે, 'Dog' એ 'Animal' છે. આ Inheritance નો મૂળભૂત સિદ્ધાંત છે.

Q2. નીચેનામાંથી કયો Inheritance નો પ્રકાર નથી?

Beginner
A Hierarchical Inheritance B Single Inheritance C Multilevel Inheritance D Double Inheritance
Show answer & explanation

Double Inheritance

Inheritance ના મુખ્ય પ્રકારો Single, Multilevel, Hierarchical અને Multiple છે. 'Double Inheritance' એ કોઈ માન્ય પ્રકાર નથી.

Q3. Child class parent class ના કયા members ને વારસામાં મેળવી શકતો નથી?

Beginner
A બધા members ને વારસામાં મેળવી શકે છે B Protected members C Public members D Private members
Show answer & explanation

Private members

Child class parent class ના private members ને વારસામાં મેળવી શકતો નથી. તે ફક્ત public અને protected members ને જ વારસામાં મેળવે છે.

Q4. નીચેનામાંથી કયો સંબંધ Inheritance માટે યોગ્ય છે?

Beginner
A Student અને Course B Cat અને Animal C Car અને Engine D Book અને Page
Show answer & explanation

Cat અને Animal

'Cat' અને 'Animal' વચ્ચે 'is-a' સંબંધ છે (Cat એ Animal છે). બાકીના વિકલ્પો 'has-a' સંબંધ દર્શાવે છે, જે composition માટે યોગ્ય છે.

Q5. Multilevel Inheritance માં કેટલા levels હોઈ શકે છે?

Beginner
A માત્ર ત્રણ B માત્ર એક C માત્ર બે D કોઈ મર્યાદા નથી, પરંતુ ઊંડી hierarchy ટાળવી જોઈએ
Show answer & explanation

કોઈ મર્યાદા નથી, પરંતુ ઊંડી hierarchy ટાળવી જોઈએ

Multilevel Inheritance માં levels ની કોઈ નિશ્ચિત મર્યાદા નથી, પરંતુ ખૂબ ઊંડી inheritance hierarchies જટિલતા વધારે છે અને તેને ટાળવી જોઈએ.

Q6. Java ભાષા Multiple Inheritance ને કેવી રીતે સપોર્ટ કરે છે?

Beginner
A Interfaces નો ઉપયોગ કરીને B ફક્ત single inheritance ને જ સપોર્ટ કરે છે C તે Multiple Inheritance ને બિલકુલ સપોર્ટ કરતી નથી D સીધા જ બહુવિધ classes માંથી વારસો મેળવીને
Show answer & explanation

Interfaces નો ઉપયોગ કરીને

Java Multiple Inheritance ને સીધું સમર્થન આપતી નથી કારણ કે તે 'diamond problem' તરફ દોરી શકે છે. તેના બદલે, Java interfaces નો ઉપયોગ કરીને બહુવિધ વર્તણૂકો પ્રાપ્ત કરવાની મંજૂરી આપે છે.

Q7. Inheritance નો ઉપયોગ કરતી વખતે સૌથી મહત્વપૂર્ણ શું છે?

Beginner
A ફક્ત એક જ level નો ઉપયોગ કરવો B Code ને ફરીથી લખવાનું ટાળવું C બધા members public હોવા જોઈએ D 'is-a' સંબંધ હોવો જોઈએ
Show answer & explanation

'is-a' સંબંધ હોવો જોઈએ

Inheritance નો ઉપયોગ કરતી વખતે સૌથી મહત્વપૂર્ણ બાબત એ છે કે બે classes વચ્ચે 'is-a' સંબંધ હોવો જોઈએ. ફક્ત code reusability માટે Inheritance નો ઉપયોગ કરવો યોગ્ય નથી.

Q8. નીચેનામાંથી કયું વિધાન Inheritance વિશે સાચું છે?

Beginner
A Inheritance polymorphism ને સમર્થન આપે છે B Inheritance હંમેશા code ને સરળ બનાવે છે C Inheritance નો ઉપયોગ ફક્ત GUI frameworks માં થાય છે D Inheritance માં child class parent class ના બધા members ને બદલી શકે છે
Show 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 છે?

Beginner
A Hierarchical Inheritance B Multiple Inheritance C Multilevel Inheritance D Single Inheritance
Show answer & explanation

Hierarchical Inheritance

આ Hierarchical Inheritance છે કારણ કે એક parent class ('Vehicle') ને બહુવિધ child classes ('Car', 'Bike', 'Truck') છે.

Q10. Inheritance નો ઉપયોગ કરીને તમે શું પ્રાપ્ત કરી શકો છો?

Beginner
A ફક્ત data hiding B Code reusability અને polymorphism C ફક્ત polymorphism D ફક્ત code reusability
Show answer & explanation

Code reusability અને polymorphism

Inheritance code reusability અને polymorphism બંને પ્રાપ્ત કરવામાં મદદ કરે છે. Code reusability દ્વારા તમારે code ફરીથી લખવાની જરૂર નથી, અને polymorphism દ્વારા તમે parent class ના reference દ્વારા child class ના ઑબ્જેક્ટને સંભાળી શકો છો.

Q11. ખૂબ ઊંડી inheritance hierarchy ની શું સમસ્યા છે?

Beginner
A તે code ને જટિલ અને સમજવામાં મુશ્કેલ બનાવે છે B તે code ને વધુ ઝડપી બનાવે છે C તે compiler ને ધીમું કરે છે D તે memory નો વધુ ઉપયોગ કરે છે
Show answer & explanation

તે code ને જટિલ અને સમજવામાં મુશ્કેલ બનાવે છે

ખૂબ ઊંડી inheritance hierarchy code ને જટિલ અને સમજવામાં મુશ્કેલ બનાવે છે. તેનાથી code ની જાળવણી કરવી મુશ્કેલ બને છે અને bugs શોધવામાં સમય લાગે છે. સારી પ્રેક્ટિસ એ છે કે hierarchy ને શક્ય તેટલી છીછરી (shallow) રાખવી.

Q12. Inheritance ફક્ત code reusability માટે ઉપયોગી છે.

Beginner
A True B False
Show answer & explanation

False

Inheritance ફક્ત code reusability માટે જ નહીં, પરંતુ સંબંધોને મોડેલ કરવા, code ને સંગઠિત કરવા અને polymorphism ને સમર્થન આપવા માટે પણ ઉપયોગી છે.

Q13. Child class parent class ના private members ને વારસામાં મેળવી શકે છે.

Beginner
A True B False
Show answer & explanation

False

Child class parent class ના private members ને વારસામાં મેળવી શકતો નથી. તે ફક્ત public અને protected members ને જ વારસામાં મેળવે છે.

Q14. Inheritance શું છે? સમજાવો.

Beginner
Show answer & explanation

—

આ મૂળભૂત વ્યાખ્યા છે.

Q15. Parent class અને Child class વચ્ચે શું સંબંધ છે?

Beginner
Show answer & explanation

—

આ સંબંધ 'is-a' તરીકે ઓળખાય છે.

Q16. Single Inheritance નું ઉદાહરણ આપો.

Beginner
Show answer & explanation

—

આ સૌથી સરળ પ્રકારનો Inheritance છે.

Q17. Multilevel Inheritance નું ઉદાહરણ આપો.

Beginner
Show answer & explanation

—

આમાં inheritance ની સાંકળ બને છે.

Q18. Hierarchical Inheritance નું ઉદાહરણ આપો.

Beginner
Show answer & explanation

—

એક માતા-પિતા, અનેક બાળકો.

Q19. Inheritance નો મુખ્ય ફાયદો શું છે?

Beginner
Show answer & explanation

—

આ Inheritance ના મુખ્ય ફાયદા છે.

Q20. Child class parent class ના કયા members ને વારસામાં મેળવી શકતો નથી?

Beginner
Show answer & explanation

—

આ members ફક્ત parent class માં જ ઉપલબ્ધ છે.

Building up · 11 questions

Q21. Multiple Inheritance શું છે? તેની મર્યાદા શું છે?

Intermediate
Show answer & explanation

—

આ એક મહત્વપૂર્ણ ખ્યાલ છે.

Q22. Inheritance અને Composition વચ્ચે શું તફાવત છે?

Intermediate
Show answer & explanation

—

આ બે અલગ અલગ પ્રકારના સંબંધો છે.

Q23. GUI Frameworks માં Inheritance નો ઉપયોગ કેવી રીતે થાય છે?

Intermediate
Show answer & explanation

—

આનાથી GUI components ને એકસમાન રીતે સંભાળી શકાય છે.

Q24. Polymorphism સાથે Inheritance નો શું સંબંધ છે?

Intermediate
Show answer & explanation

—

એક જ interface, અનેક વર્તણૂકો.

Q25. Game Development માં Inheritance નો ઉપયોગ કેવી રીતે થાય છે?

Intermediate
Show answer & explanation

—

આનાથી દુશ્મનોને એકસમાન રીતે સંભાળી શકાય છે.

Q26. Data Structures માં Inheritance નો ઉપયોગ કેવી રીતે થાય છે?

Intermediate
Show answer & explanation

—

આનાથી data structures ને એકસમાન રીતે સંભાળી શકાય છે.

Q27. નીચેનામાંથી કયો સંબંધ Inheritance (વારસા) માટે સૌથી યોગ્ય છે?

Intermediate
A Book (પુસ્તક) અને Library (પુસ્તકાલય) વચ્ચેનો સંબંધ B Dog (કૂતરો) અને Animal (પ્રાણી) વચ્ચેનો સંબંધ C Car (કાર) અને Engine (એન્જિન) વચ્ચેનો સંબંધ D Student (વિદ્યાર્થી) અને School (શાળા) વચ્ચેનો સંબંધ
Show 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 કૉલ કરી શકાય છે?

Intermediate
A માત્ર 'openTrunk()' B માત્ર 'startEngine()' અને 'stopEngine()' C 'startEngine()', 'stopEngine()' અને 'openTrunk()' ત્રણેય D માત્ર 'startEngine()' અને 'openTrunk()'
Show 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 મળે છે?

Intermediate
A 'SportsCar', 'Car' અને 'Vehicle' ત્રણેય class ના members B 'SportsCar' અને 'Car' class ના members, પરંતુ 'Vehicle' class ના નહીં C માત્ર 'SportsCar' class ના members D માત્ર 'Vehicle' અને 'SportsCar' class ના members
Show answer & explanation

'SportsCar', 'Car' અને 'Vehicle' ત્રણેય class ના members

Multilevel Inheritance માં, દરેક child class તેના તમામ પૂર્વજો (ancestors) પાસેથી members વારસામાં મેળવે છે. અહીં 'SportsCar' એ 'Car' નું child છે અને 'Car' એ 'Vehicle' નું child છે, તેથી 'SportsCar' ને ત્રણેય class ના members મળે છે.

Q30. નીચેનામાંથી કયું વિધાન Inheritance (વારસા) ના ઉપયોગ વિશે સાચું છે?

Intermediate
A Inheritance નો ઉપયોગ ફક્ત code reusability (કોડ પુનઃઉપયોગિતા) માટે થાય છે. B Inheritance નો ખરો હેતુ classes વચ્ચે 'is-a' સંબંધને મોડેલ કરવાનો છે. C Inheritance નો ઉપયોગ ફક્ત GUI frameworks માં જ થાય છે. D Inheritance નો ઉપયોગ કરવાથી code હંમેશા સરળ અને ઓછો જટિલ બને છે.
Show 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 છે?

Intermediate
A Single Inheritance B Hierarchical Inheritance C Multiple Inheritance D Multilevel Inheritance
Show 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 નો ઉપયોગ કરતી વખતે શું ધ્યાન રાખવું જોઈએ?

Advanced
Show answer & explanation

—

આ બે સામાન્ય ભૂલો છે.

Q33. Inheritance નો ખરો હેતુ શું છે?

Advanced
Show 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 નું આઉટપુટ શું હશે?

Advanced
A Runtime error: field hiding causes ambiguity B Generic sound C Bark D Compilation error: cannot override private field
Show 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 નું આઉટપુટ શું હશે?

Advanced
A 10\nClass A: 10 B 10\nClass C: 30 C 10\nClass C: 30 D 30\nClass C: 30
Show 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 નું આઉટપુટ શું હશે?

Advanced
A Hello from Child\nChild instance B Hello from Parent\nChild instance C Compilation error: cannot override static methods D Hello from Parent\nParent instance
Show 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 નું આઉટપુટ શું હશે?

Advanced
A 10\n10 B 20\n20 C Compilation error: cannot access private field in superclass D 20\n10
Show 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 નું આઉટપુટ શું હશે?

Advanced
A A\nB\nC B Compilation error: cannot resolve super in multiple inheritance C C\nA\nB D A\nC\nB
Show 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 કરે છે, અન…

Make your own

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