<< Chapter < Page Chapter >> Page >

What does Flanagan have to say?

Here is how David Flanagan, author of Java in a Nutshell, summarizes his discussion of member classes.

"A class defined as a member (non-static) of another. Each instance has an enclosing instance, and can use its members. New syntax for this , new , and super . Cannot have static members. Cannot have same name as containing class."

According to Flanagan, the main features of member classes are:

  • Every instance of a member class is internally associated with an instance of the class that defines or contains the member class.
  • The methods of a member class can implicitly refer to the fields defined within the member class, as well as those defined by any enclosing class,including private fields of the enclosing class.

Smoke and mirrors

Every class definition in a Java program, including nested top-level classes, member classes, local classes, and anonymous classes, produces a class file whenthe program is compiled. According to Flanagan,

"The Java Virtual Machine knows nothing about nested top-level classes and interfaces or the various types of inner classes. Therefore, the Javacompiler must convert these new types into standard non-nested class files that the Java interpreter can understand. This is done through source codetransformations that insert $ characters into nested class names. These source code transformations may also insert hidden fields, methods, andconstructor arguments into the affected classes."

A reference to the containing object

For example, the compiler automatically inserts a private instance variable in the member class to hold a reference to the containing object. It alsoinserts a hidden argument in all constructors for the member class, and passes the containing object's reference to the constructor for the member class. Themodified constructor saves that reference in the private instance variable of the object of the member class. Thus each object instantiated from the memberclass contains a private reference to the containing object.

Accessing private members

In those cases where it is necessary for an object of the member class to access private members of the containing object, the compiler automaticallycreates and uses accessor methods that make such access possible.

Similar to your code

The bottom line is that the code that is automatically produced by the compiler is probably very similar to code that you would write if you werewriting the program using only of top-level classes. The good news is that you don't have to write that extra code, and you don't have to maintain it. Theextra code is written for you, and if you modify your class structure, the extra code is automatically modified accordingly.

Discussion and sample code

The paragraphs that follow will explain a program named InnerClasses06 , which is designed specifically to illustrate various characteristics of memberclasses. I will discuss the program in fragments. A complete listing is shown in Listing 25 near the end of the module.

Questions & Answers

Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
hi
Loga
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask