-1

Example

Does the property and the field in the PyCharm refer to the same concept of attribute in the oops, or not?

Is there any difference between the items?

Which one of the followings is the attribute concept of the oops?

I need to know what is the difference between both of the items... I didn't find a correct answer here... I am new to OOPs, so please make the answers simple, but understandable too.

Danny220
  • 25
  • 8

2 Answers2

1

A field is a variable that is declared within a class or object, and it represents a specific piece of data. It is usually accessed directly, without any additional logic or processing.

A property, on the other hand, is a way to provide controlled access to a field.
It defines a getter and/or a setter method that can be used to retrieve or modify the field's value. Properties can also include additional logic or validation to ensure that the field's value is always valid.

In Object-Oriented Programming (OOP), the term attribute typically refers to a piece of data that is associated with an object. An attribute is a characteristic or property of an object that describes its state or behavior.

Out of the given options, field is the attribute concept of OOP.
Reason:
Attributes in OOP are variables that define the state or behavior of an object, and they can be either instance or class variables. By defining attributes within a class, developers can create objects that represent real-world entities and define their properties and behaviors in a structured and consistent way

Snell
  • 89
  • 8
0

The one with the underscore should be the private field of the class. Use the one without it, wich controls the private one.

Danny220
  • 25
  • 8
  • why its known as private field of a class...what is a private field? what is a field? – Pranav S V Apr 27 '23 at 10:00
  • A private field, often identified with an underscore by convection, is a field which can be used only by the class itself. A field is the rappresentation of a public property of an object (class). You wanna access the private fields with public gets and sets of the property. Read more at [this answer](https://stackoverflow.com/a/295109/21310672) – Danny220 Apr 27 '23 at 10:06