Explain OOPS Concepts with examples
Anonimo
Following are the OOPs concepts with example: 1. Encapsulation Encapsulation means keeping data safe inside a class. You control who can see or change the data. Example: A bank account class that only lets you check your balance or deposit money, but not directly change the balance. 2. Abstraction Abstraction is about hiding complex details and showing only what’s necessary. It makes things easier to use. Example: A shape class that tells you how to calculate an area, but doesn’t show all the math behind it. 3. Inheritance Inheritance lets a new class use features from an existing class. It helps reuse code. Example: A dog class that inherits from an animal class. The dog class can use animal features without rewriting them. 4. Polymorphism Polymorphism means a single action can work in different ways depending on the object. Example: A function that makes animals speak. Both a dog and a cat can use the same function, but they will say different things.