Reputation: 93
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
Reputation: 2876
Enumeration (Enum) its a type/structure of data that represents a limited group of possible values
Also Enumeration (Interface) is an interface to make enumerations of collections of objects
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
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
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