This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes acc ss modifier in array declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "acc ss modifier in array declarations " Watch "acc ss modifier in array declarations " New topic
Author

acc ss modifier in array declarations

w.k.hasintha
Greenhorn

Joined: Oct 11, 2006
Posts: 4
can arrays be declared private ,public or protected .we have compilation errors while doing so why does this happen ?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Where are you trying to declare array as private, public or protected. I mean at class level or method level.

Method level variables can't be declared as private, public, protected or static.



Try to compile this, it will not raise error
babudev Yam
Greenhorn

Joined: Jul 27, 2006
Posts: 8
Array is also an object and so it cannot be treated like an field variable in a class.

Maybe thats reason.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023

Array is also an object and so it cannot be treated like an field variable in a class.


Why? If it is true then Ali'scode will have compile time errors.
babudev Yam
Greenhorn

Joined: Jul 27, 2006
Posts: 8
Yeah correct

It doesnt make sense to give modifier to something declared in a method as it is local anyway !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: acc ss modifier in array declarations
 
Similar Threads
1D array
String args[]
Trouble with compiling?
String array
how to calculate number of arguments in a function