How to pass an object that is calling a method as an argument to the method in Java?

I have a method called PositionSetter in a class called Ship. It needs a Board object as a parameter. Every Board object is supposed to call the PositionSetter method, and pass itself as an argument. How do I do this?
Code:

public void PositionSetter(Board BattleshipBoard, Ship ship)
{
  //do stuff with BattleshipBoard and ship  
}

Again, the object that’s calling the above method, is a Board object that needs to pass itself as an argument.
Alternaives to my approach are welcome.

P.S. I’m a noob, so please bear with me. Please suggest edits rather than downvoting.


Source: oop

Leave a Reply