OOP Report English Formatted
OOP Report English Formatted
1. Encapsulation
In C#, encapsulation allows bundling data and methods within classes. Access modifiers
such as `private`, `public`, `protected`, and `internal` control the visibility of properties and
methods, enabling encapsulation and restricting direct access to an object's data.
Example:
2. Inheritance
Inheritance allows a new class to inherit attributes and methods from an existing class,
which reduces code redundancy and enables hierarchical classification.
Example:
3. Polymorphism
Polymorphism in C# allows objects of different classes to be treated as objects of a common
superclass. This can be achieved using virtual methods and method overriding.
Example:
public class Animal {
public virtual void Speak() {
Console.WriteLine("Animal sound");
}
}
4. Abstraction
Abstraction in C# can be achieved using abstract classes and interfaces, which allow
defining methods without implementing them. This hides complex details and provides a
simplified interface.
Example: