Data abstraction is the process of hiding certain details and showing only essential information to the user.
Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next chapter).
The abstract
keyword is used for classes and methods:
- Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
- Abstract method: can only be used in an abstract class, and it does not have a body. The body is provided by the derived class (inherited from).
An abstract class can have both abstract and regular methods:
abstract class mcn {
public int add(int a, int b) {
return (a + b);
}
}
class mcn1: mcn {
public int mul(int a, int b) {
return a * b;
}
}
class test {
static void Main(string[] args) {
mcn1 ob = new mcn1();
int result = ob.add(5, 10);
Console.WriteLine("the result is {0}", result);
}
}