Java object | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Java object

What happened when we pass an object as an argument?

4th Feb 2018, 8:26 PM
Faisal Rahman
Faisal Rahman - avatar
2 Answers
+ 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.
5th Feb 2018, 1:42 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 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.
4th Feb 2018, 8:45 PM
Jacob Pembleton
Jacob Pembleton - avatar