• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static class variables and Constructors  RSS feed

 
Ntuthuko Khwezi Makukule
Greenhorn
Posts: 5
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when importing static class variables. Why are they only accessible in the calling class's constructor (user defined) and methods?
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "importing static class variables". Normally you only import classes (and interfaces and enums), and not variables. So could you provide an example of what you mean by that?

I'm also not sure what you mean by "calling class" there. What is it that you think the class is calling?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming he meant importing static class members but I'm not quite clear on the question either...
 
Ntuthuko Khwezi Makukule
Greenhorn
Posts: 5
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when importing base class members. Why are they only accessible in the derived class's constructor (user defined) and methods, but not in the class definition?



 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fail to see the problem. You have given those fields public access, so they are visible in the subclasses.
If you mean why cannot you write isbn "978 123 45678 9"; outside a method: that is because that is a statement and statements must be inside methods or similar.

It is of course poor design to make fields public; unless a field represents a global constant it should always be private.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!