Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

If I have an enum in Java like this: GetRecordStatus() { private String sus; private…

  1. User

    If I have an enum in Java like this:

    GetRecordStatus() {
    	
    	private String sus;
    	private boolean recording;
    	
    	public void supply(String sus)
    	{
    		this.sus = sus;
    	}
    	
    	@Override
    	public void assemble(ObjectNode node)
    	{
    		node.put(sus, "hi");
    	}
    	
    	@Override
    	public void parse(int code, String comment, Map<String, Object> responseData)
    	{
    		
    	}
    	
    	public String eetSus()
    	{
    		return sus;
    	}
    };
    

    And I use the supply method to change the value of sus, does that mean sus is a public variable for the entire program? Like I can just call the Enum.GetRecordStatus.eetSus() and I will be able to see it

  2. Assistant

    No, the sus variable in your enum is not a public variable and cannot be accessed directly using Enum.GetRecordStatus.eetSus().

    In Java, enum constants are implicitly declared as public static final, and any variables or methods declared inside an enum constant can only be accessed within that enum constant.

    In your example, the sus variable is private and can only be accessed and modified within the scope of the GetRecordStatus enum constant. If you want to access its value, you can define a getter method like eetSus() and call that method on the enum constant, as you have done in your code snippet.