• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance Problem

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello everyone,
I understand inheritance perfectly well but I'm still new at programming with it and I know for a fact that this code is dreadful. There are 2 main problems that I've identified but have no idea how to solve.

1st: When I declare a constructor for SerieTV or EpisodeTV the compiler tell me "cannot find constructor Film()". I've tried adding a constructor Film(){} in the class Film and running it but then the compiler points at it saying NAME might not be initialized.

2nd: NAME is meant to stay private inside the parent class Film. If the son classes want to know its value they must use the method getName(). The problem with that is that I don't know how to initialize NAME because the compiler tells me it has private access... which technically makes sense.

Any ideas or suggestion? :roll:
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through the Java� Tutorials, and this section describes constructors.

After you read that, you will know that each constructor must start with
  • Invoking an overloaded constructor of the same class with the this(xyz) syntax
  • OR: Invoking a constructor of the superclass with the super(xyz) syntax,
  • But not both.
  • The exception to that rule is when the superclass has an accessible no-arguments constructor; in your instance because you didn't write super(something) the compiler is looking for a no-arguments constructor and complaining because it can't find that constructor.
     
    Campbell Ritchie
    Sheriff
    Posts: 48382
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    By the way, I would suggest some stylistic improvements:
  • Because there is a java type called List, please change the name "list" to something different; "episodes" might be a good suggestion.
  • Although "NAME" is final, you are not using it as a constant, so it would be better to call it "name."
  • Good luck with it, or should I say "merde!"
     
    Guido Sautter
    Ranch Hand
    Posts: 142
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Campbell,

    you probably mean "bonne chance" ... "merde" means something you might be tempted to say if things go finally wrong ... like "m***** f***in' shit"
     
    Olivier Legat
    Ranch Hand
    Posts: 176
    Chrome Mac Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Excellent. Thanks for your help Campbell Ritchie. I fixed the problem(s)

     
    Campbell Ritchie
    Sheriff
    Posts: 48382
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So no longer "merde?"
     
    Olivier Legat
    Ranch Hand
    Posts: 176
    Chrome Mac Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Indeed. "Merde" no more thanks to you.
     
    Campbell Ritchie
    Sheriff
    Posts: 48382
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You're welcome, or is it ca ne fait rien?
     
    Olivier Legat
    Ranch Hand
    Posts: 176
    Chrome Mac Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    actually it's "de rien"
     
    Campbell Ritchie
    Sheriff
    Posts: 48382
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Merci.

    I should have stopped French when I left school
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic