Answer the question
In order to leave comments, you need to log in
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;
}
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question