This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

inner class  RSS feed

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package foo;
public class Outer
public static class Inner
Which statement true?
a. An instance of the Inner class can be constructed
statement with "new Outer.Inner()"
b. An instance of the Inner class can't be constructed
outside of package foo
c. An instance of the Inner class can only be constructed
from within the Outer class
d. From within the package bar, an instance of the Inner
class can be constructed statement with "new Inner()"
ans : a) but Why is b incorrect? Isnt b true since tha package statement is declared??
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,
You're correct. You can create a <code>Outer.Inner</code> class from outside the package. The following two examples compile and run without error.

Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
kevin goon
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your reply
I tried to compile your coding but for some reason it didnt work. I throws NoClassDefFoundException
Let me just make sure if I understood right.
So the answer choice B would be incorrect from my original question right?? since you CAN create instance outside package b importing the file.
How about if you remove the import statement from your subclass? Then it wouldnt work?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!