117k views
5 votes
Which of the following is a valid constructor header for the Player class that accepts the player name as a parameter? public void Player(String playerName) private Player(playerName) private void Player(playerName) public Player(String playerName)

User Jiamo
by
3.3k points

1 Answer

2 votes

Answer: Player(String playerName)

Step-by-step explanation:

A constructor is a code block of a class. It is always witnessed when a new instance of the class is created

In JAVA , a valid constructor header is given as " CLASS (parameter)"

here, Class → Player

parameter → player name (which is a string)

So, a valid constructor header for the Player class that accepts the player name as a parameter: Player(String playerName)

User Til
by
3.1k points