• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Nested top-level class .....

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per Marcus Mock test 3 Qno) 38
Is the following statement true/false.
"a nested top-level class cannot declare any static variables, static methods, or static initializers."
As per my understanding, "a nested top-level class " is a static inner class, i think the statement above is False.
Static inner class can include static vars, methods, static initializers if the class is static.
can anyone verify this!
Thanks.

 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you compile the following code:
<PRE>public class Test {
static class S{
static int i;
static void m(){}
static {
i = 1;
}
}
}</PRE>
[This message has been edited by Tony Alicea (edited February 28, 2000).]
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, if you mean this type of class, then the answer is no, you cannot have these <CODE>static</CODE> things inside it.
<PRE>public class Test {
class S{
static int i; //Wrong
static void m(){} //Wrong
static { //Wrong
i = 1;
}
}
}</PRE>
 
Hold that thought. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic