• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

acc ss modifier in array declarations

 
w.k.hasintha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can arrays be declared private ,public or protected .we have compilation errors while doing so why does this happen ?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah correct

It doesnt make sense to give modifier to something declared in a method as it is local anyway !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic