Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interesting question from javacross! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interesting question from javacross!" Watch "Interesting question from javacross!" New topic

Interesting question from javacross!

Noel Hinders
Ranch Hand

Joined: Jan 13, 2001
Posts: 44
Hi all ,
this is an interesting question from simulation
An existing class JC now needs some additional functionality which it is proposed to add with a nested or inner class, NEC. You have been able to establish the following requirements
1. There will probably be more than one JC instance active in the appilcation so the solution has to work no matter how many JC instances are there
2. NEC will need to have access to instance methods and variables as well as static variables
3]. More than one method in JC will have to have access to a method of NEC
Which configuration of nested class is the best bet for the problem

a]. A static class
b]. A member inner class
c]. An inner class defined in a JC method
d]. An anonymous inner class
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Option b. A member inner class is correct. That is the one which satisfies all the requirements!!

Sun Certified Programmer for Java 2 Platform
Noel Hinders
Ranch Hand

Joined: Jan 13, 2001
Posts: 44
Hi can anyone explain me the solution.
Thanks in advance.
Ishaan Mohan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
a) If the inner class is static then NEC will not be able to access to instance methods and variables other then the Static ones.
c)& d) If the inner class is defined in a method or a annonymous then it can access only the final variables of the function, not all.
I agree. Here's the link:
subject: Interesting question from javacross!
It's not a secret anymore!