Advertisement
Intermediate C# Programming, C# Language Fundamentals

Why is class an abstract data type?

Short answer

A class is considered an abstract data type because it defines a blueprint that combines both data, in the form of fields and properties, and behavior, in the form of methods, while hiding the internal implementation details from the code that uses it.

Save C# Programming mock interview
Advertisement
AModel answer
A class is considered an abstract data type because it defines a blueprint that combines both data, in the form of fields and properties, and behavior, in the form of methods, while hiding the internal implementation details from the code that uses it. Users of a class only need to know what operations are available through its public methods and properties, not how those operations are implemented internally, which is the core idea behind abstraction and encapsulation in object oriented programming.
public class BankAccount {
    private decimal _balance;
    public void Deposit(decimal amount) {
        _balance += amount; // internal detail hidden from callers
    }
    public decimal GetBalance() { return _balance; }
}
Real-world example
A banking application exposes a BankAccount class with simple Deposit and Withdraw methods, while the actual internal logic for validating transactions and updating balances remains completely hidden from the code that uses the account.
Likely follow-ups
  • What is the difference between abstraction and encapsulation?
  • How does an abstract class differ from a regular class?
Related topics