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

Static imports

Ntuthuko Khwezi Makukule
Greenhorn

Joined: May 11, 2014
Posts: 5

When importing static members of a class. Why are they only accessible within the constructor of the calling class, and not outside of it?
Here's the source code to help understand my question.



Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

Ntuthuko Khwezi Makukule wrote:When importing static members of a class. Why are they only accessible within the constructor of the calling class, and not outside of it?


Please explain what you mean by "not outside of it".

Thanks,
Henry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Welcome to the Ranch

I have added code tags, which you should always use, and doesn't your post look better
No, you can use static imports in any parts of the class. Apart from a public non‑final field being very poor design, this works:-By the way: package names should be lower‑case throughout.
Ntuthuko Khwezi Makukule
Greenhorn

Joined: May 11, 2014
Posts: 5

Henry Wong wrote:
Please explain what you mean by "not outside of it".


if the static members were accessed outside the constructor.
Ntuthuko Khwezi Makukule
Greenhorn

Joined: May 11, 2014
Posts: 5

Campbell Ritchie
Thanks for the help
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

Ntuthuko Khwezi Makukule wrote:
Henry Wong wrote:
Please explain what you mean by "not outside of it".


if the static members were accessed outside the constructor.


Again, you need to explain what that means. For example, I can do this...




This won't compile... but the reason has nothing to do with the static import, because this...



Won't compile either.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static imports