C
C
Clazzer1232019-07-18 12:49:35
Python
Clazzer123, 2019-07-18 12:49:35

Can anyone explain the definitions?

Can anyone explain with an example what is an attribute, an instance of a class, a method, an object?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gomonov, 2019-07-18
@Clazzzer123

class Car:
    max_speed = ''  # атрибут от же свойство свойство

    def ride(self, speed, distance):  # метод
        self.distance = distance
        self.speed = speed

car = Car()  # объект, он же экземпляр класса
car.max_speed = 120
car.ride()

To understand: an object is a noun, a method is a verb (what an object can do), properties are adjectives that describe a noun, i.e. an object

D
Dmitry Arushanov, 2019-07-18
@daruwanov

class A {
   public $name =  123 ; // Атрибут класса 

   public function sayMyName() { // метод
     echo $this->name;
  }

}
$a = new A(); // $a экземпляр класса

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question