How to swap or exchange objects in Java? - GeeksforGeeks
How to swap objects in Java?
Let's say we have a class called "Car" with some attributes. And we create two objects of Car, say car1 and car2, how to exchange the data of car1 and car2?
A Simple Solution is to swap members. For example, if the class Car has only one integer attribute say "no" (car number), we can swap cars by simply swapping the members of two cars.
Read full article from How to swap or exchange objects in Java? - GeeksforGeeks
No comments:
Post a Comment