When creating a method inside a class if you use the parameter:
public String Method(ClassName NewObject){}
or in my example below:
public String EqualsTo(Deck aCard){}
will it create a new object of that class within that method? If not anyone mind explaing what I is happening with that parameter?
NOTE: Disregard any minor syntax errors as I just constructed this to get my question across better so this is not a complete class.
import java.util.Scanner;
import java.util.Random;
public class Deck {
private int suit;
private int rank;
private Random generator = new Random();
Scanner in = new Scanner(System.in);
//Default constructor
public Deck() {
suit = suit.random(4);
rank = rank.random(13);
}
public String EqualsTo(Deck aCard){}
}
Objects are created when you use the
newkeyword. On the other hand, when you declare a method asit says that the
EqualsTo()method takes aDeckreference as a parameter. In order to use the method, you need to create aDeckobject and keep a reference to it. Then you send the reference to the method.