<< 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

Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
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