Moaaz Ali
Moaaz Ali

Reputation: 93

Enum returning statement

What if I have an interface and the interface has inside it a method that return a type Enumerator, in the classes that implement the interface how should I write the return statement? like:

public enum Day 
{
    Saturday,Sunday....
}

public interface blabla 
{  
    public Day getDay(); 
}

public class blabla2 implements blabla 
{ 
    public Day getDay() 
    { 
        return ???? what should I write here ?
    }
}

Upvotes: 0

Views: 107

Answers (3)

Dubas
Dubas

Reputation: 2876

Enumeration (Enum) its a type/structure of data that represents a limited group of possible values

JavaDoc Enum

Also Enumeration (Interface) is an interface to make enumerations of collections of objects

Java Doc Enumeration

If "Enum" the returning value can be any of the Enum set.

public enum Day {
    Saturday,
    Sunday
    ...
}

public Day getDay()  { 
    return Day.Saturday;
}

Upvotes: 0

Colin D
Colin D

Reputation: 5661

Just return the whatever Day is appropriate.

In the code below, I return the enum value for Saturday.

    public enum Day 
    {
        Saturday,Sunday;
    }

    public interface blabla 
    {  
        public Day getDay(); 
    }

    public class blabla2 implements blabla 
    { 
        public Day getDay() 
        { 
            return Day.Saturday;
        }
    }

Upvotes: 0

Thomas
Thomas

Reputation: 88707

return ???? what should I write here ?

Well, it depends on how you determine the day to return, but if the day is fixed, you could write

public Day getDay() 
{ 
  return Sunday; //or Day.Sunday depending on your imports and package
}

Upvotes: 1

Related Questions