• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

modifiers question from dan's exam

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
class Z {
void m1() {
abstract class A {} // 1
final class B {} // 2
private class C {} // 3
protected class D {} // 4
public class E {} // 5
static class F {} // 6
synchronized class G {} // 7
transient class H {} // 8
volatile class I {} // 9
strictfp class J {} // 10
}
}
Which of the follow class declarations results in a compiler error?
ans is 3,4,5,6,7,8,9,
synchronized,volatile,transient are field modifiers, so 7,8,9, correct, but why? 3,4,5,6.
anybody correct me?
thx
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Anushree
The reason is :
Inner Classes inside methods(local classes) may not be declared as private, coderanch, protected, or static(jNotes)
All this classes are inside m1() method.

Regards,
Jamal Hasanov
www.j-think.com
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private, coderanch, protected and static are not applicable to local variables either. They make no sense within a method because the local variables are not accesible from outside the method. Thus, why trying to specify the access modifiers or static.
reply
    Bookmark Topic Watch Topic
  • New Topic