+ 2
Java object
What happened when we pass an object as an argument?
2 ответов
+ 3
Lets say you have a class named “cls” with 2 int values: x and y...
public void printCoords(cls obj) {
System.out.println(obj.x);
System.out.println(obj.y);
}
This will output its x and y position. You will also find other reasons to pass an object as an argument, this is just a basic example.
+ 4
It works just like passing any other data type as an argument. You can think of a class as a new data type that you created.