<< Chapter < Page Chapter >> Page >

Accessing private members

In those cases where it is necessary for an object of the local 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 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 InnerClasses07 . This program is designed specifically to illustrate various characteristics of localclasses. I will discuss the program in fragments. A complete listing is shown in Listing 17 near the end of the module.

This program illustrates the use of local classes. The program consists of a total of five classes:

  • Four top-level classes named
    • InnerClasses07
    • A
    • X
    • Y
  • A local class named B.

When compiled, the program produces the class files shown in Figure 1 . The file named A$1$B.class represents the local class. The remaining files in Figure 1 represent the four top-level classes.

Class hierarchy

In the previous module, I explained that once you understand the class file naming convention, you can determine from the filenames how top-level classes and member classes are structured. However, the situation isn't nearly so clear when it comes to local classes and anonymousclasses. This will become more apparent in the next module, which combines local classes and anonymous classes.

Overall program structure and behavior

Containment hierarchy

The program named InnerClasses07 defines a local class named B inside an instance method named meth .

The method named meth is an instance method of a top-level class named A . The method named meth instantiates two separate objects of the local class named B , and calls a method named showB on each of them.

The method named showB displays certain data values that illustrate the characteristics of localclasses, as well as the containment hierarchy among objects of the local class and an object of the containing class.

In this case, objects of the class named B are contained within an object of the class named A . (The class named A is an enclosing class of the class named B .)

Inheritance hierarchy

The top-level class named A extends the top-level class named X , (which in turn, extends Object ).

The class named B is contained in or enclosed by the top-level class named A , but extends the top-level class named Y , (which in turn, extends Object ).

There is no inheritance relationship between the classes X and Y (aside from their common superclass named Object ).

There is no inheritance relationship between the classes A and B .

The method named showB also displays data values that are intended to demonstrate that the inheritance hierarchy is independent of thecontainment hierarchy.

Questions & Answers

I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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