View Full Version : Basic enum question (Java)

January 9th, 2010, 08:14 AM
Here is my simplistic incomplete program:

public class GraphicsInformation
public static void main (String[] args){
for(GraphicCards Card: GraphicCards.values()){
System.out.printf("%s %s \n", Card, Card.getVideoRAM());

public enum GraphicCards

//private int weirdNumber; // find out real name
private String videoRAM;

GraphicCards(String videoRam){
this.videoRAM = videoRAM;
public String getVideoRAM(){
return videoRAM;


My question is: Why is it printing out null twice?

Any help would be greatly appreciated!
Thanks in advance!

January 9th, 2010, 09:59 AM
My guess is that you mispelled in the constructor:

this.videoRAM = videoRAM;

while the parameter name is "videoRam" (note RAM/Ram), so it is assigned its automatic-set value null ;) There are no errors in your code, this works for me:

package rs18.enumtest;

public class Main {

public enum GraphicCard {

public String ram = "";

GraphicCard(String videoRAM) {
this.ram = videoRAM;

public static void main(String[] args) {
for (GraphicCard card : GraphicCard.values())
System.out.printf("%s: %s video RAM%n", card, card.ram);


Since you seem new to Java, please follow Java coding guidelines about member case and other things :D

January 13th, 2010, 08:02 AM
Sorry for the late response (Just came back to this thread now) and thanks for catching my typo. It solved my issue. :)