MCQOPTIONS
Saved Bookmarks
This section includes 44 Mcqs, each offering curated multiple-choice questions to sharpen your C Sharp Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Which of the following statements are correct about the C#.NET code snippet given below? namespace IndiabixConsoleApplication { class index { protected int count; public index() { count = 0; } } class index1: index { public void increment() { count = count +1; } } class MyProgram { static void Main(string[] args) { index1 i = new index1(); i.increment(); } } }count should be declared as public if it is to become available in the inheritance chain. count should be declared as protected if it is to become available in the inheritance chain. While constructing an object referred to by i firstly constructor of index class will be called followed by constructor of index1 class. Constructor of index class does not get inherited in index1 class. count should be declared as Friend if it is to become available in the inheritance chain. |
| A. | 1, 2, 5 |
| B. | 2, 3, 4 |
| C. | 3, 5 |
| D. | 4, 5 |
| E. | None of these |
| Answer» C. 3, 5 | |
| 2. |
How can you make the private members inheritable? |
| A. | By making their visibility mode as public only |
| B. | By making their visibility mode as protected only |
| C. | By making their visibility mode as private in derived class |
| D. | It can be done both by making the visibility mode public or protected |
| Answer» E. | |
| 3. |
The private members of the base class are visible in derived class but are not accessible directly. |
| A. | True |
| B. | False |
| Answer» B. False | |
| 4. |
If a derived class object is created, which constructor is called first? |
| A. | Base class constructor |
| B. | Derived class constructor |
| C. | Depends on how we call the object |
| D. | Not possible |
| Answer» B. Derived class constructor | |
| 5. |
While inheriting a class, if no access mode is specified, then which among the following is true? (in C++) |
| A. | It gets inherited publicly by default |
| B. | It gets inherited protected by default |
| C. | It gets inherited privately by default |
| D. | It is not possible |
| Answer» D. It is not possible | |
| 6. |
Members which are not intended to be inherited are declared as ________________ |
| A. | Public members |
| B. | Protected members |
| C. | Private members |
| D. | Private or Protected members |
| Answer» D. Private or Protected members | |
| 7. |
If a base class is inherited in protected access mode then which among the following is true? |
| A. | Public and Protected members of base class becomes protected members of derived class |
| B. | Only protected members become protected members of derived class |
| C. | Private, Protected and Public all members of base, become private of derived class |
| D. | Only private members of base, become private of derived class |
| Answer» B. Only protected members become protected members of derived class | |
| 8. |
Which access type data gets derived as private member in derived class? |
| A. | Private |
| B. | Public |
| C. | Protected |
| D. | Protected and Private |
| Answer» B. Public | |
| 9. |
Which type of inheritance leads to diamond problem? |
| A. | Single level |
| B. | Multi-level |
| C. | Multiple |
| D. | Hierarchical |
| Answer» D. Hierarchical | |
| 10. |
Which is the correct syntax of inheritance? |
| A. | class derived_classname : base_classname{ /*define class body*/ }; |
| B. | class base_classname : derived_classname{ /*define class body*/ }; |
| C. | class derived_classname : access base_classname{ /*define class body*/ }; |
| D. | class base_classname :access derived_classname{ /*define class body*/ }; |
| Answer» D. class base_classname :access derived_classname{ /*define class body*/ }; | |
| 11. |
Which among the following is correct for a hierarchical inheritance? |
| A. | Two base classes can be used to be derived into one single class |
| B. | Two or more classes can be derived into one class |
| C. | One base class can be derived into other two derived classes or more |
| D. | One base class can be derived into only 2 classes |
| Answer» D. One base class can be derived into only 2 classes | |
| 12. |
Which programming language doesn’t support multiple inheritance? |
| A. | C++ and Java |
| B. | C and C++ |
| C. | Java and SmallTalk |
| D. | Java |
| Answer» E. | |
| 13. |
Which among the following is correct for multiple inheritance? |
| A. | class student{public: int marks;}s; class stream{int total;}; class topper:public student, public stream{ }; |
| B. | class student{int marks;}; class stream{ }; class topper: public student{ }; |
| C. | class student{int marks;}; class stream:public student{ }; |
| D. | class student{ }; class stream{ }; class topper{ }; |
| Answer» B. class student{int marks;}; class stream{ }; class topper: public student{ }; | |
| 14. |
Which among the following best defines single level inheritance? |
| A. | A class inheriting a derived class |
| B. | A class inheriting a base class |
| C. | A class inheriting a nested class |
| D. | A class which gets inherited by 2 classes |
| Answer» C. A class inheriting a nested class | |
| 15. |
How many basic types of inheritance are provided as OOP feature? |
| A. | 4 |
| B. | 3 |
| C. | 2 |
| D. | 1 |
| Answer» B. 3 | |
| 16. |
Which among the following best describes the Inheritance? |
| A. | Copying the code already written |
| B. | Using the code already written once |
| C. | Using already defined functions in programming language |
| D. | Using the data and functions into derived segment |
| Answer» E. | |
| 17. |
Creating a derived class from a base class requires fundamental changes to the base class. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 18. |
It is illegal to make objects of one class as members of another class. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 19. |
The size of a derived class object is equal to the sum of sizes of data members in base class and the derived class. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 20. |
A class D can be derived from a class C, which is derived from a class B, which is derived from a class A. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 21. |
Private members of base class cannot be accessed by derived class member functions or objects of derived class. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 22. |
If a base class and a derived class each include a member function with the same name, the member function of the derived class will be called by an object of the derived class |
| A. | 1 |
| B. | |
| Answer» B. | |
| 23. |
If a base class contains a member function func(), and a derived class does not contain a function with this name, an object of the derived class cannot access func(). |
| A. | 1 |
| B. | |
| C. | 1 |
| D. | |
| Answer» C. 1 | |
| 24. |
We can derive a class from a base class even if the base class's source code is not available. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 25. |
Which of the following are reuse mechanisms available in C#.NET? Inheritance Encapsulation Templates Containership Polymorphism |
| A. | 1, 4 |
| B. | 1, 3 |
| C. | 2, 4 |
| D. | 3, 5 |
| Answer» B. 1, 3 | |
| 26. |
Which of the following statements are correct about Inheritance in C#.NET? A derived class object contains all the base class data. Inheritance cannot suppress the base class functionality. A derived class may not be able to access all the base class data. Inheritance cannot extend the base class functionality. In inheritance chain construction of object happens from base towards derived. |
| A. | 1, 2, 4 |
| B. | 2, 4, 5 |
| C. | 1, 3, 5 |
| D. | 2, 4 |
| Answer» D. 2, 4 | |
| 27. |
An object of a derived class cannot access private members of base class. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 28. |
Which of the following is correct about the C#.NET snippet given below? namespace IndiabixConsoleApplication { class Baseclass { public void fun() { Console.WriteLine("Hi" + " "); } public void fun(int i) { Console.Write("Hello" + " "); } } class Derived: Baseclass { public void fun() { Console.Write("Bye" + " "); } } class MyProgram { static void Main(string[ ] args) { Derived d; d = new Derived(); d.fun(); d.fun(77); } } } |
| A. | The program gives the output as: Hi Hello Bye |
| B. | The program gives the output as: Bye Hello |
| C. | The program gives the output as: Hi Bye Hello |
| D. | Error in the program |
| Answer» C. The program gives the output as: Hi Bye Hello | |
| 29. |
Assume class B is inherited from class A. Which of the following statements is correct about construction of an object of class B? |
| A. | While creating the object firstly the constructor of class B will be called followed by constructor of class A. |
| B. | While creating the object firstly the constructor of class A will be called followed by constructor of class B. |
| C. | The constructor of only class B will be called. |
| D. | The constructor of only class A will be called. |
| Answer» C. The constructor of only class B will be called. | |
| 30. |
There is no private or protected inheritance in C#.NET. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 31. |
In an inheritance chain which of the following members of base class are accessible to the derived class members? static protected private shared public |
| A. | 1, 3 |
| B. | 2, 5 |
| C. | 3, 4 |
| D. | 4, 5 |
| Answer» C. 3, 4 | |
| 32. |
The way a derived class member function can access base class public members, the base class member functions can access public member functions of derived class. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 33. |
Which of the following statements is correct about the C#.NET program given below? namespace IndiabixConsoleApplication { class Baseclass { int i; public Baseclass(int ii) { i = ii; Console.Write("Base "); } } class Derived : Baseclass { public Derived(int ii) : base(ii) { Console.Write("Derived "); } } class MyProgram { static void Main(string[ ] args) { Derived d = new Derived(10); } } } |
| A. | The program will work correctly only if we implement zero-argument constructors in Baseclass as well as Derived class. |
| B. | The program will output: Derived Base |
| C. | The program will report an error in the statement base(ii). |
| D. | The program will work correctly if we replace base(ii) with base.Baseclass(ii). |
| Answer» E. | |
| 34. |
Which of the following should be used to implement a 'Has a' relationship between two entities? |
| A. | Polymorphism |
| B. | Templates |
| C. | Containership |
| D. | Encapsulation |
| Answer» D. Encapsulation | |
| 35. |
There is no multiple inheritance in C#.NET. That is, a class cannot be derived from multiple base classes. |
| A. | 1 |
| B. | |
| C. | 1 |
| D. | |
| Answer» B. | |
| 36. |
How can you prevent inheritance from a class in C#.NET ? |
| A. | Declare the class as shadows. |
| B. | Declare the class as overloads. |
| C. | Declare the class as sealed. |
| D. | Declare the class as suppress. |
| Answer» D. Declare the class as suppress. | |
| 37. |
Which of the following statements are correct about the C#.NET code snippet given below? namespace IndiabixConsoleApplication { class index { protected int count; public index() { count = 0; } } class index1: index { public void increment() { count = count +1; } } class MyProgram { static void Main(string[] args) { index1 i = new index1(); i.increment(); } } } count should be declared as public if it is to become available in the inheritance chain. count should be declared as protected if it is to become available in the inheritance chain. While constructing an object referred to by i firstly constructor of index class will be called followed by constructor of index1 class. Constructor of index class does not get inherited in index1 class. count should be declared as Friend if it is to become available in the inheritance chain. |
| A. | 1, 2, 5 |
| B. | 2, 3, 4 |
| C. | 3, 5 |
| D. | 4, 5 |
| Answer» C. 3, 5 | |
| 38. |
Which statement will you add in the function fun() of class B, if it is to produce the output "Welcome to IndiaBIX.com!"? namespace IndiabixConsoleApplication { class A { public void fun() { Console.Write("Welcome"); } } class B: A { public void fun() { // [*** Add statement here ***] Console.WriteLine(" to IndiaBIX.com!"); } } class MyProgram { static void Main (string[ ] args) { B b = new B(); b.fun(); } } } |
| A. | base.fun(); |
| B. | A::fun(); |
| C. | fun(); |
| D. | mybase.fun(); |
| Answer» B. A::fun(); | |
| 39. |
Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities? |
| A. | Polymorphism |
| B. | Containership |
| C. | Templates |
| D. | Encapsulation |
| Answer» E. | |
| 40. |
Multiple inheritance is different from multiple levels of inheritance. |
| A. | 1 |
| B. | |
| C. | 1 |
| D. | |
| Answer» B. | |
| 41. |
What will be the output of the C#.NET code snippet given below? namespace IndiabixConsoleApplication { class Baseclass { public void fun() { Console.Write("Base class" + " "); } } class Derived1: Baseclass { new void fun() { Console.Write("Derived1 class" + " "); } } class Derived2: Derived1 { new void fun() { Console.Write("Derived2 class" + " "); } } class Program { public static void Main(string[ ] args) { Derived2 d = new Derived2(); d.fun(); } } } |
| A. | Base class |
| B. | Derived1 class |
| C. | Derived2 class |
| D. | Base class Derived1 class |
| Answer» B. Derived1 class | |
| 42. |
What will be the size of the object created by the following C#.NET code snippet? namespace IndiabixConsoleApplication { class Baseclass { private int i; protected int j; public int k; } class Derived: Baseclass { private int x; protected int y; public int z; } class MyProgram { static void Main (string[ ] args) { Derived d = new Derived(); } } } |
| A. | 24 bytes |
| B. | 12 bytes |
| C. | 20 bytes |
| D. | 10 bytes |
| Answer» B. 12 bytes | |
| 43. |
Which of the following statements should be added to the subroutine fun( ) if the C#.NET code snippet given below is to output 9 13? class BaseClass { protected int i = 13; } class Derived: BaseClass { int i = 9; public void fun() { // [*** Add statement here ***] } } |
| A. | Console.WriteLine(base.i + " " + i); |
| B. | Console.WriteLine(i + " " + base.i); |
| C. | Console.WriteLine(mybase.i + " " + i); |
| D. | Console.WriteLine(i + " " + mybase.i); |
| Answer» C. Console.WriteLine(mybase.i + " " + i); | |
| 44. |
Which of the following can be facilitated by the Inheritance mechanism? Use the existing functionality of base class. Overrride the existing functionality of base class. Implement new functionality in the derived class. Implement polymorphic behaviour. Implement containership. |
| A. | 1, 2, 3 |
| B. | 3, 4 |
| C. | 2, 4, 5 |
| D. | 3, 5 |
| Answer» B. 3, 4 | |