Within the movie type I want to create an enum variable named genre which holds the genre's that can be applied to the movie. However I am not sure how I go about inheriting this enum variable to the bluray and dvd class.
Just make it a member of the movie type that isn't private
. (Or just an enum in the same package, outside the movie type.) Then the bluray and dvd classes will have access to it.
Example:
Movie.java
:
public class Movie {
public enum Genre {
Horror,
SciFi,
RomCom
};
protected Genre genre;
public Movie(Genre g) {
this.genre = g;
}
}
BluRay.java
:
public class BluRay extends Movie {
public BluRay(Genre g) {
super(g);
}
}
Note that Genre
doesn't have to be within Movie
at all, and you may well be better off if it isn't (just in the same package or similar). But if you want Genre
in Movie
, you can have it there.
Side note: You didn't ask for feedback on your design, but FWIW I probably wouldn't make Genre
an enum, because then you have to recompile in order to add genres, which seems like a common operation.