<< 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 mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
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