Object Oriented Programming

Object Oriented Programming

Object-oriented programming uses objects in programming, the main reason to use oops in a code is to increase the reusability of a code. There are more core concepts in oop these are

-Class

-Object

-Abstraction

-Encapsulation

-Polymorphism

-Inheritance

These all provide a better programming style. We will discuss all gradually today we will discuss class and object.

Class: Class is a blueprint or template for object creation. using a class we can create as many objects as we want.

Object: An object is an instance of a class. Objects have two characteristics states and behaviors. An attribute represents its state and a method represents its behaviors. Using its method we can modify its state.

In short, every object has these properties

-Identity: Every object is uniquely identified.

-State: An attribute of an object representing the state of an object.

-Behavior: An object method represent its behavior.

Python is an Object-Oriented Programming language, so everything in Python is treated as an object. An object is a real-life entity. It is the collection of various data and functions that operate on those data.

Here is an example of OOP (class and object)

here "Fruit" is a class "name" and "color" are attributes we are accessing those attributes for " fruit1" and "fruit2" objects. We can reuse this as many as we want.

No alt text provided for this image
example of OOP(class and object)

要查看或添加评论,请登录

Ananna Chowdhury Giti的更多文章

社区洞察

其他会员也浏览了