Interview question for programming in C#.


OOPS Concepts, Access Modifier, Constructor, Destructor

1. What are the basic concepts of object oriented programming?

It is necessary to understand some of the concepts used extensively in object oriented programming.These include Objects Classes Data abstraction and encapsulation Inheritance Polymorphism Dynamic Binding Message passing.

2. What is object?

An object is an instance of a class. An object is created by using operator new. A class that creates an object in memory will contain the information about the values and behaviours (or methods) of that specific object.

3. What is encapsulation?

The wrapping up of data and functions into a single unit (called class) is known as encapsulation. Encapsulation containing and hiding information about an
object, such as internal data structures and code.

4. What is inheritance?

Inheritance is deriving the new class from the already existing one.

5. Define polymorphism?

Polymorphism means one name, multiple forms. It allows us to have more than one function with the same name in a program.It allows us to have overloading of operators so that an operation can exhibit different behaviours in different instances.

6. What is the use of abstract keyword?

The modifier abstract is a keyword used with a class, to indicate that this class cannot itself have direct instances or objects, and it is intended to be only a 'base' class to other classes.

7. What are the features of abstract class?

An abstract class cannot be instantiated, and it is an error to use the new operator on an abstract class. An abstract class is permitted (but not required) to contain abstract methods and accessors. An abstract class cannot be scaled.

8. What is an interface class?

It is an abstract class with public abstract methods all of which must be implemented in the inherited classes.

9. What is meant by method overloading?

Method overloading permits multiple methods in the same class to have the same name as long as they have unique signatures. When compiling an invocation of an overloaded method, the compiler uses overload resolution to determine the specific method to invoke.

10. what is an abstract base class?

An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function.

11. How is method overriding different from method overloading?

When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

12. What is difference between Class And Interface?

Class : is logical representation of object. It is collection of data and related sub procedures with defination. Interface : is also a class containg methods which is not having any definations.Class does not support multiple inheritance. But interface can support.

13. What is a base class?

A class declaration may specify a base class by following the class name with a colon and the name of the base class. omitting a base class specification is the same as deriving from type object.

14. Can you inherit multiple interfaces?

Yes. Multiple interfaces may be inherited in C#.

15. Does c# support multiple inheritance?

No,its impossible which accepts multi level inheritance.

16. Can you override private virtual methods?

No, private methods are not accessible outside the class.

17. What is the difference between Object and Instance?

An instance of a user-defined type is called an object. We can instantiate many objects from one class. An object is an instance of a class.

18. What are the modifiers in C#?

Abstract Sealed Virtual Const Event Extern Override Readonly Static New

19. What are the types of access modifiers in C#?

Access modifiers in C# are : public protect private internal internal protect

20. Define scope?

Scope refers to the region of code in which a variable may be accessed.

21. What is the difference between private and public keyword?

Private : The private keyword is the default access level and most restrictive among all other access levels. It gives least permission to a type or type member. A private member is accessible only within the body of the class in which it is declared. Public : The public keyword is most liberal among all access levels, with no restrictions to access what so ever. A public member is accessible not only from within, but also from outside, and gives free access to any member declared within the body or outside the body.

22. What is the difference between public, static and void?

public :The keyword public is an access modifier that tells the C# compiler that the Main method is accessible by anyone. static :The keyword static declares that the Main method is a global one and can be called without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created. void : The keyword void is a type modifier that states that the Main method does not return any value.

23. Define destuctors?

A destructor is called for a class object when that object passes out of scope or is explicitly deleted.A destructors as the name implies is used to destroy the objects that have been created by a constructors.Like a constructor , the destructor is a member function whose name is the same as the class name but is precided by a tilde.

24. Define Constructors?

A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created.It is called constructor because it constructs the values of data members of the class.

25. Can “this” be used within a static method?

No ‘This’ cannot be used in a static method. As only static variables/methods can be used in a static method.

26. What is difference between constants, readonly and, static ?

Constants: The value can’t be changed. Read-only: The value will be initialized only once from the constructor of the class. Static: Value can be initialized once.

Other Topics

. 27. What is ENUM?

Enum are used to define constants.

28. What is the difference between ref & out parameters?

An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.

29. What is serialization?

Serialization is the process of converting an object into a stream of bytes. De-serialization is the opposite process of creating an object from a stream of bytes. Serialization / De-serialization is mostly used to transport objects.

30. What are the difference between Structure and Class?

Structures are value type and Classes are reference type Structures can not have contractors or destructors. Classes can have both contractors and destructors. Structures do not support Inheritance, while Classes support Inheritance.

31. What is Delegates?

Delegates are a type-safe, object-oriented implementation of function pointers and are used in many situations where a component needs to call back to the component that is using it.

32. What are the types of errors?

Syntax error Logic error Runtime error

33. What is a code group?

A code group is a set of assemblies that share a security context.

34. What are sealed classes in C#?

The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class.

35. What is the difference between Array and Arraylist?

An array is a collection of the same type. The size of the array is fixed in its declaration. A linked list is similar to an array but it doesn’t have a limited size.

36. What is the difference between console and window application?

A console application, which is designed to run at the command line with no user interface. A Windows application, which is designed to run on a user’s desktop and has a user interface.

37. What is the difference between Array and LinkedList?

Array is a simple sequence of numbers which are not concerned about each others positions. they are independent of each others positions. adding,removing
or modifying any array element is very easy. Compared to arrays ,linked list is a comlicated sequence of numbers.

38. Does C# have a throws clause?

No, unlike Java, C# does not require the developer to specify the exceptions that a method can throw.

39. Does C# support a variable number of arguments?

Yes, uisng the params keyword. The arguments are specified as a list of arguments of a specific type.

40. What is a multi cast delegates?

It is a delegate that points to and eventually fires off several methods.