Skip to main content

Posts

Showing posts from April, 2024

C# : Interview questions (16-20)

     Questions : Can you im plement multiple interfaces in C#? What is a namespace in C#? Explain the c oncept of encapsulation. What is a constru ctor in C#? Differentiate betw een a class and an object. C# : Interview questions (11-15) Answers : Implementing Multiple Interfaces in C#: Yes, C# allows a class to implement multiple interfaces, enabling it to define behaviour specified by each interface. Multiple interfaces can be separated by commas in the class declaration. interface IShape { void Draw () ; } interface IMovable { void Move () ; } class Circle : IShape , IMovable { public void Draw () { Console.WriteLine( "Drawing a circle..." ); } public void Move () { Console.WriteLine( "Moving the circle..." ); } } In this example, the Circle class implements both the IShape and IMovable interfaces, providing concrete implementations for the Draw and Move methods defined by each interfac...

C# : Interview questions (11-15)

   Questions : What is i nheritance in C#? Explain the c oncept of method overloading. What is method overriding? What is an abst ract class in C#? What is an inte rface? C# : Interview questions (6-10 ) Answers : Inher itance in C#: Inheritance is a fundamental feature of object-oriented programming (OOP) that allows a class (called a subclass or derived class) to inherit properties and behaviors from another class (called a superclass or base class). In C#, inheritance is implemented using the : symbol followed by the name of the base class. class Animal // Base class { public void Eat () { Console.WriteLine( "Animal is eating..." ); } } class Dog : Animal // Derived class inheriting from Animal { public void Bark () { Console.WriteLine( "Dog is barking..." ); } } In this example, the Dog class inherits the Eat method from the Animal class, allowing instances of Dog to both eat and bark. Method Overload...

C# : Interview questions (6-10)

 Questions : What is the difference between stack and heap memory? How do you declare a variable in C#? Explain the use of the "var" keyword in C#. What are the different access modifiers in C#? How does C# support polymorphism? C# : Interview questions (1-5) Answers : Difference between Stack and Heap Memory Stack and heap are two types of memory used by computer programs, including those written in C#. Here's how they differ: Stack Memory: Stack memory is used for storing local variables and function call information. It operates in a Last In, First Out (LIFO) manner, where the last item added is the first to be removed. Memory allocation and deallocation on the stack are fast because it involves adjusting the stack pointer. Stack memory is limited in size and is typically smaller than heap memory. Stack memory is automatically managed by the compiler or runtime environment. Heap Memory: Heap memory is used for dynamic memory allocation, where memory is allocated and de...