<< Chapter < Page Chapter >> Page >
(Note that while the containment hierarchy of local classes is independent of the inheritance hierarchy, it is technically possible toestablish an inheritance relationship between a local class and one of its enclosing classes. For example, by making a couple of minor modifications,it is possible to cause the local class B in this program to extend the enclosing class A instead of the top-level class Y .)

The controlling class

The entire controlling class named InnerClasses07 , including the main method and a static variable named baseTime , is shown in Listing 1 .

The static variable named baseTime is initialized with the current date and time in milliseconds (relative to January 1, 1970). This static variable is used later as a base to establish the relative points in time thatcertain activities occur during the execution of the program.

The main method

The main method shown in Listing 1 instantiates a new object of the class named A and calls the method named meth on that object.

This method will sequentially instantiate two separate objects of a local class named B that is defined inside the method named meth . Then the method named meth will call a method named showB on each of those objects, causing them to display data values that illustrate the characteristicsof local classes.

The class named X

The top-level class named X is shown in Listing 2 .

The class named A extends this class to illustrate the difference between the inheritance hierarchy and the containment hierarchy. Note that thisclass defines and initializes a protected instance variable, which will be accessed later to illustrate the inheritance hierarchy.

(Somewhat surprisingly, you will also see later that this protected instance variable belonging to the superclass of the enclosing class A is also accessible by methods belonging to an object of the local class viathe containment hierarchy.)

The class named Y

The top-level class named Y is shown in Listing 3 .

The local class named B extends this class to illustrate the difference between the inheritance hierarchy and the containment hierarchy.

Note that this class defines and initializes a protected instance variable. It alsooverrides the toString method, which is inherited from the Object class.

The instance variable and the overridden toString method will be accessed later to illustrate the inheritance hierarchy.

The class named A

The code in Listing 4 shows the beginning of the top-level class named A .

This code declares and initializes a private instance variable named aTime , which establishes the relative time that an object of class A is instantiated.

This private instance variable will be accessed directly by code belonging to an object of the local class B , which is contained by an object of the class A .

Listing 4 also shows the constructor for class A , which displays the time whenever an object is instantiated from class A .

The screen output

The code shown earlier in the main method of Listing 1 instantiates an object of class A . This causes the screen output shown in Figure 2 .

(Note that the relative time output value on your system may be different, depending on the speed of your system and the impact of otherapplications that may be running concurrently.)

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
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
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