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

Superclass encapsulation

Stephen Black
Ranch Hand

Joined: Aug 13, 2009
Posts: 50

In the superclass I have
Instance variables set to private CHECK
Setter methods as needed CHECK
Setter methods marked as public CHECK

But when I try to use the setter in the subclass
I get an error saying that I have an invalid method declaration

Here is the supertype code which I have abbreviated


And here is the subtype on which I am trying to set the inherited instance variables to something useful


I know that if I just set the variables to public I can access them directly but apparently that is bad encapsulation
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

That code you have in your NYStyleCheesePizza class needs to be inside a method (or a constructor). The only things which can be outside methods (or constructors) are declarations, so the compiler is trying to interpret that code as declarations. And it fails (naturally, because they aren't declarations) and so it gives you error messages.
Stephen Black
Ranch Hand

Joined: Aug 13, 2009
Posts: 50

Ok only instance variables and methods and constructors (if needed) go into a class
Note to self "Make sure you only put instance variables methods and constructors in a class "
Got it Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Superclass encapsulation