Câu hỏi phỏng vấn C#
Câu hỏi

Can you explain the difference between Interface , abstract...

Câu trả lời

Certainly! Here's an explanation of the differences between Interface, abstract class, sealed class, static class, and partial class in C#:

Interface

  • An interface is a contract that defines a set of methods, properties, events, or indexers that a class or struct must implement.
  • It provides a way to achieve abstraction and define common functionality across different types.
  • A class can implement multiple interfaces, but it can only inherit from one base class.
  • Interfaces do not provide any implementation details; they only define the signature of the members.

Abstract Class

  • An abstract class is a base class that cannot be instantiated directly.
  • It can provide both abstract and non-abstract (concrete) methods, properties, events, and indexers.
  • A class can only inherit from one base class, which can be an abstract class.
  • Abstract classes can have constructors, destructors, and access modifiers for their members.
  • Abstract classes can provide default method implementations and allow derived classes to override them.

Sealed Class

  • A sealed class is a class that cannot be inherited from, and its methods cannot be overridden.
  • Sealing a class prevents other classes from inheriting from it and modifying its behavior.
  • Sealing a method prevents derived classes from overriding that specific ...
senior

senior

Gợi ý câu hỏi phỏng vấn

senior

What is a static constructor?

senior

What is the best practice to have best performance using Lazy objects?

middle

What is the use of Null Coalescing Operator ( ?? ) in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào