aspose file tools*
The moose likes Beginning Java and the fly likes Inheritance Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance Problem" Watch "Inheritance Problem" New topic
Author

Inheritance Problem

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176



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:


Olly
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    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

    Joined: Dec 22, 2004
    Posts: 142
    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

    Joined: Nov 17, 2007
    Posts: 176

    Excellent. Thanks for your help Campbell Ritchie. I fixed the problem(s)

    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    So no longer "merde?"
    Olivier Legat
    Ranch Hand

    Joined: Nov 17, 2007
    Posts: 176

    Indeed. "Merde" no more thanks to you.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    You're welcome, or is it ca ne fait rien?
    Olivier Legat
    Ranch Hand

    Joined: Nov 17, 2007
    Posts: 176

    actually it's "de rien"
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    Merci.

    I should have stopped French when I left school
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Inheritance Problem