Note that there are some explanatory texts on larger screens.

plurals
  1. POOverlapping object in Java
    primarykey
    data
    text
    <p>I created 2 instances of my class player, but it seems as though the last instance created always takes over (overlaps?) all of the other objects, what is the issue here? (i am a beginner when it comes to programming)</p> <p>Here is the program:</p> <pre><code>public class Test { public static void main (String[] args) { Player player1 = new Player("Player 1"); Player player2 = new Player("Player 2"); Player player3 = new Player("Player 3"); System.out.println(player1.getName()); } } </code></pre> <p>This is the output</p> <pre><code>Player 3 </code></pre> <p>And this is the class</p> <pre><code>import java.util.Scanner; import java.util.Random; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Player { public static String name; public static int score; public static Die[] dice = new Die[5]; public static JRadioButton[] rerollButton = new JRadioButton[5]; //---------------------------------------------------------------- // Constructor - initialize values //---------------------------------------------------------------- public Player(String n) { name = n; score = 0; // initialize all dice and rerollButtons in their respective arrays for (int i = 0; i &lt; 5; i++) { dice[i] = new Die(); rerollButton[i] = new JRadioButton(); } } public String getName() { return name; } } </code></pre> <p>I have tried to look for other similar questions but every one i found was far to complex for me to really understand. Any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload