Junior — Middle
Can you list the main characteristics of objects in object-oriented programming?
sobes.tech AI
Answer from AI
Main characteristics of objects in object-oriented programming (OOP):
- State (fields/attributes) — data that describes the object.
- Behavior (methods) — functions or procedures that the object can perform.
- Identity — the uniqueness of the object, allowing it to be distinguished from others.
In C#, objects are created based on classes that define these characteristics. For example:
public class Car
{
public string Color { get; set; } } // state
public void Drive() // behavior
{
Console.WriteLine("The car is driving");
}
}
Here, the Car object has a state (color) and behavior (Drive method).