E
E
Exito2018-05-28 20:22:29
Java
Exito, 2018-05-28 20:22:29

Static Methods in Java. Why is it possible to use an object as a parameter?

Hello. Not so long ago I started my acquaintance with Java and already faced difficulties. As I understood from what I read, static methods in Java only work with static variables. But recently, in one of the examples, I saw how an object was used as a parameter of a static method and no error occurred. This begs the question: how is this possible? After all, a variable specified in the parameters of a static method can refer to an object that will not even be created.
Example code:
first file

public class Car {
  int ID;
}

second file:
public class TestCar {

  public static void main(String[] args) {

  }
  
  public static void carTest(Car myCar) {

  }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-05-28
@Exito

You misunderstood. Anything can be used as parameters of a static method. Here it is direct in your example - String[] args in Main - a statics or not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question