• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Superclass encapsulation

 
Ranch Hand
Posts: 52
1
MySQL Database Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 52
1
MySQL Database Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic