



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This document contains important and frequently asked questions in interviews or exams. If you have less time to study but want to go through some important queries before going for interviews/exams, it will help you for sure.
Typology: Quizzes
1 / 5
This page cannot be seen from the preview
Don't miss anything!
1. Can we use “this” keyword in static method in C#? Answer: We cannot use "this" keyword inside the static method as "this" keyword returns a reference to the current instance of a class and we don’t use any instance to call static members of a class instead we call them by using the class name. 2. What is the difference between break and continue statement? Answer: Use ‘break’ statement when you want to jump out of the loop and use ‘continue’ statement when you want to jump over an iteration and continue the loop execution. 3. What is the difference between finally and finalize blocks? Answer: ‘finally’ block gets executed with try and catch. ‘finally’ block always gets executed after try and catch block whether exception is caught or not. ‘finalize’ method is called just before the garbage collection. It is automatically called when an instance is not being called or used. It is used to clean up the unmanaged code. 4. What is thread? Answer: A thread is a set of instructions. On execution of thread, a program performs concurrent processing (more than one process at a time). Thread follows a life cycle where it starts whenever a thread is created and gets terminated immediately after the execution. 5. Can you inherit Enum in C#? Answer: NO, you cannot inherit Enum as it is sealed by default. 6. What is pure virtual function? Answer:
A pure virtual function/method is a method whose implementations are not provided in the base class, hence it is implemented in the derived class.
7. What is coupling in OOP? Answer: The degree of dependency between the components is called coupling. 8. What are the operators that cannot be overloaded? Answer: All the operators except the + operator cannot be overloaded. 9. If you have two classes Base and Child and Child class inherit Base class so which class’s constructor will be called first when creating an object of Child class? Answers: Base class constructor will be called first. 10. Can we give the return type of a constructor? Answer: No, we cannot give the return type of a constructor. 11. What would be the output of below program? namespace ConsoleApplication { public class Program { static void Main(string[] args) { Base obj=new Child(); obj.result(); Console.ReadLine(); } } public class Base { public void result() { Console.WriteLine("Base method"); } }
Answer: Output: Child method
13. What would be the output of below set of codes? Enum name { A, B, C, D, } name.A= 10; Console.WriteLine(“name.B”); Answer: It will throw an error as enum element cannot be assigned a value outside the enum declaration. 14. Can you allow a class to be inherited but prevent methods from being overridden in c#? Answer: Yes, we can allow a class to be inherited by declaring the class public and prevent methods from being overridden by making the methods sealed. 15. Does C# support multiple inheritance? Answer: C# supports multiple inheritance of interfaces but not of classes. 16. Is string a value type or reference type in C#? Answer: string is an object (reference type). 17. What is the purpose of the base
keyword in C#? Answer: The ‘base’ keyword is used to call a method or constructor in the base class from a derived class.
18. What is a delegate in C#? Answer: A delegate is a type that represents reference to methods. It allows you to pass methods as parameters to other methods or store them in variables. 19. Can you have a private interface in C#? Answer: No, interface can only have public access modifiers. 20. What is the difference between ‘IEnumerable’ and ‘IEnumerator? Answer: 'IEnumerable' represents a collection that can be enumerated, while 'IEnumerator' allows you to iterate through the elements of the collection one by one.