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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

JQ+ Non Static Inner Class NEW RULE !

 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Q#ID : 958227370580
which of the following statements regarding inner classes are true ?
1. A non static inner class may have static members
2. Anonymous inner classes cannot have any 'extends' or 'implements' clause.
3. Anonymous inner classes can only be created for interfaces
4. Anonymous inner classes can never have initialization parameters.
5. Anonymous inner classes cannot be static.
the answer given is : 1,2,5
I tought the only 2 and 5 are correct,
for answer 1, JQ+ said :
Option Comment : "If you make them final"
General Comment :
"...Erlier, Non static inner clasess were not allowed to have static fields at all. THIS RULE IS NOW MODIFIED, and the new rule says that :
The third paragraph of the section members that can be marked static is amended to make an exception and allow inner classes to declare static FINAL fields that are compile time constants as members.
Ex.
public class Outer {
class inner {
static final int k = 0;
}
}
Geee....IS IT TRUE ???
I tried, but it give me compile error !!
thank's
stevie
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
It compils fine. I am not sure why you have problem to compile it.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I'm closing this thread; it has been answered in a duplicate post, here http://www.javaranch.com/ubb/Forum35/HTML/000242.html
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
    Bookmark Topic Watch Topic
  • New Topic