Intern — Junior
Can you explain what is meant by an object in object-oriented programming?
sobes.tech AI
Answer from AI
In object-oriented programming, an object is an instance of a class that combines data (properties) and methods (functions) that work with this data.
Objects model real entities or abstractions, allowing the code to be organized more structurally and clearly.
For example, a class Car might have properties: color, brand, speed, and methods: drive, brake.
Example in C#:
class Car
{
public string Color;
public string Model;
public void Drive()
{
Console.WriteLine("The car is driving");
}
}
// Creating an object
Car myCar = new Car();
myCar.Color = "Red";
myCar.Model = "Toyota";
myCar.Drive();
Here, myCar is an object of the class Car.