I don;t understand how we can use same JLabel variable to create a new label. Doesn't aLabel variable here refers to the same single object(label). So how could we get 4 label ?
Can i do this behavior with other classes objects to or just with component classes?
Explanation of Step by step flow of execution of code here would be helpful.
JLabel label1 =newJLabel("First label");
add(label1, BorderLayout.NORTH);
JLabel label2 =newJLabel("Second label");
add(label2, BorderLayout.SOUTH);
JLabel label3 =newJLabel("Third label");
add(label3, BorderLayout.CENTER);
OR i can just use:
JLabel aLabel =newJLabel("First label");
add(aLabel, BorderLayout.NORTH);
aLabel =newJLabel("Second label");
add(aLabel, BorderLayout.SOUTH);
aLabel =newJLabel("Third label");
add(aLabel, BorderLayout.CENTER);