Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock question

 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I was going through a mock of 1.2 and I came across this question.

Which cannot be used in declaring and initializing an automatic (method call) variable?
A. initialized arrays (such as {"Hello","Goodbye"})
B. final
C. public
D. constant of non-primitive type
E. inner class from other scopes


I have not been able to understand this question.

Please tell me what exactly is this question asking and what does it mean.

Thanks
Kapil
 
Shilpi M Ag
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer should be public.. variables in methods are not public... but not very sure!
 
Sanyev Babu
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot declare a variable as public inside a method. Access modifiers are not applicable inside methods (for local variables) The only modifier that can be used on local variables is the final variable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic