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

What is the difference between Interface and Abstract Class?

Câu trả lời

Here is a detailed comparison of interfaces and abstract classes in C#:

Interfaces vs Abstract Classes

Defining Interfaces and Abstract Classes

  • Interface: Defines a contract that specifies a set of methods, properties, events, and indexers. Interfaces can contain only method signatures, property accessors, event accessors, and indexer accessors. They cannot contain method bodies or variable declarations.

  • Abstract Class: Serves as a base class that provides a common definition of basic functionality for related classes. Abstract classes can contain constructors, fields, methods, properties, events, and indexers. They can also contain concrete and abstract members.

Inheritance and Implementation

  • Interfaces: A class can implement multiple interfaces. Interfaces support multiple inheritance.

  • Abstract Classes: A class can inherit from only one abstract class. Abstract classes do not support multiple inheritance.

Access Modifiers

  • Interfaces: All members of an interface are implicitly public. Access modifiers cannot be used on interface members.

  • Abstract Classes: Abstract classes can have members with any access modifier (public, protected internal, protected, internal, or private).

Method Implementation

  • Interfaces: Interface methods are implicitly abstract and public. Interfaces cannot hav...
middle

middle

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

expert

What is the volatile keyword used for?

middle

What is the difference between dynamic type variables and object type variables?

junior

What is LINQ in C#?

Bình luận

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

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