What is object-oriented programming?
Interview preparation resource from Gate Smashers.
Object-oriented programming (OOP) is a programming paradigm that organizes software around objects. An object combines state, represented by data, with behavior, represented by operations or methods that can use or modify that data. Programs are designed as cooperating objects and their interactions.
Core idea
In OOP, an object represents a conceptual or real-world entity within a program. Rather than keeping data and the operations on that data entirely separate, OOP groups related state and behavior together.
State and behavior
An object's state describes its current condition, while its behavior defines what the object can do. Methods may read or change the object's state and may communicate with other objects.
- State: Data or attributes held by an object, such as its current values or properties.
- Behavior: Operations or methods that act on the object's state or interact with other objects.
Relationship to procedural programming
Procedural programming generally organizes code around procedures or functions and the sequence of actions they perform. OOP instead emphasizes objects that combine related data and behavior. In practice, many programs can use both object-oriented and procedural techniques.
