D
D
Dmitry2020-08-27 12:09:09
Java
Dmitry, 2020-08-27 12:09:09

OOP its methods, parameters, how to figure it out?

There is a .length method , it is without brackets, there are methods where you just need to put brackets, for example
method() , there are methods where you need to set parameters method(1,2) .
Question: how to find out where to put brackets and where not, where to set method parameters, and where not.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-08-27
@DegMaN

First, length without parentheses is not a method, but a field. Secondly, you can find out where it is necessary to pass parameters, and where it is not necessary, in the documentation.

S
Stalker_RED, 2020-08-27
@Stalker_RED

.length without brackets is not a method, but a property.
Go back to the beginning of the tutorial and carefully re-read about fields, methods, properties.

class Dog {
  name = 'Тузик' // поле (свойство) .name используется без скобок

  function getName() {  // метод, getName() возвращающий имя, со скобками.
    return this.name  
  }

  function move(x,y) { // метод перемещающий тузика, у него не просто скобки, туда в скобки еще координаты подставить нужно
     // ......
  }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question