-1

this is my superclass where i created an private enum

public class Media {

private String Title;
private enum Genre { Comedy, Horror, Action, Romance, Documentary, Thriller, Drama}

Genre genre;


public Media ()
{

}
public Media(String t, Genre g){

   this.Title=t;
   genre=g;

}

now i wanna use this in an subclass

public class Movies extends Media{
private String regi;
private int playtime;

public Movies(){

}

public Movies(String t, Genre g, String r, int playt)
{
    setTitle(t);
    genre=g;
    this.regi=r;
    this.playtime=playt;
}

but it is not working because its telling me that the enum is private when i send in the genre for the method of creating an Movie object? is it not possible to have a private enum and not use it in other classes or subclasses?

2 Answers2

1

Make the enum protected instead of private

protected enum Genre { Comedy, Horror, Action, Romance, Documentary, Thriller, Drama}

Private means only accessible in the class its declared.

Protected is same as private but derived classes have access to.

Public means access to all

Mohammad C
  • 1,321
  • 1
  • 8
  • 12
0

I am not an expert with Java but in the case of define visibility. You define a private member(attribute, property, method) if you want to limitate the scope to the current class. In case of want to have access from a derivate class but keeping the scope to the class or derivates you should define it as protected. I strongly recommend to read a little bit about that because it is fundamental to understand all those basic concepts.