<< Chapter < Page Chapter >> Page >

Accessing the object of the class C, and the this keyword

The syntax used with the keyword this is somewhat different for member classes and contained objects than is the case fortop-level classes. For example, continuing with the method named cShow , the code in Listing 17 shows five different ways to access the object instantiated from the member class named C in order to get and display thename of the class file that represents the member class named C.

The screen output

All five statements in Listing 17 display the name of the same class file, as shown in Figure 10 .

Obviously in this situation, the last three statements in Listing 17 are overly complex. There is no particular problem writing code in the methodnamed cShow to gain access to the object to which the method belongs. It isn't even necessary to use this to refer to that object, although the use of the hidden reference this may make the code more readable.

Accessing the containing object of the class B

However, things get a little more complicated when you need to gain access to acontaining object, such as the containing object instantiated from the class named B.

The two statements shown in Listing 18 gain access to the containing object of the class named B. Each statement gets and displays thename of the class file that represents the member class named B. (Note the use of the keyword this in these statements.)

The screen output

The output produced by the code in Listing 18 is shown in Figure 11 . Once again, both statements get and display the name of the same class file.

Accessing the containing object of the class named A

Finally, the code in Listing 19 gains access to the containing object of the class named A. (Once again, note the use of the this keyword in the statement in Listing 19 .)

The code in Listing 19 produces the output shown in Figure 12 .

(Since the class named A is a top-level class, the name of the class file is the same as the name of the class, with no $ characters inserted by thecompiler.)

Investigate independent objects of classes A and B

Recall that when the object of the member class named C was instantiated, theconstructor for the class instantiated independent objects of the enclosing classes named A and B, and saved those object's references in instancevariables of the class named C.

(See Listing 11 , noting the parameter values of 10 and 20 passed to the constructors for A and B. Recall that the constructors for A and B savethose parameter values in private instance variables named aVar and bVar .)

Display variable values and class file names

The code in Listing 20 displays the values stored in the private instance variables belonging to thoseobjects. The code in Listing 20 also displays the names of the class files representing the classes from which those objects were instantiated.

Screen output

The code in Listing 20 produces the output shown in Figure 13 .

There should be no surprises in the output shown in Figure 13 . The values of the instance variables match the parameter values passed to theconstructors in Listing 11 when the objects were instantiated. The class file names match what you already know to be true from previous discussionsearlier in this module.

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
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
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
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?