AreaPerPerson( )
method, itself. The first line of
AreaPerPerson( )
is
public void AreaPerPerson() {
This line declares a method called
AreaPerPerson
that has no parameters. It is specified as
public
, so it can be used by all other parts of the program. Its return type is
void
. Thus,
AreaPerPerson( )
does not return a value to the caller. The line ends with the opening curly
brace of the method body.
The body of
AreaPerPerson( )
consists solely of this statement:
Console.WriteLine(" " + Area / Occupants + " area per person");
This statement displays the area-per-person of a building by dividing
Area
by
Occupants
.
Since each object of type
Building
has its own copy of
Area
and
Occupants
, when
AreaPerPerson( )
is called, the computation uses the calling object’s copies of those
variables.
The
AreaPerPerson( )
method ends when its closing curly brace is encountered. This
causes program control to transfer back to the caller.
www.freepdf-books.com
Do'stlaringiz bilan baham: |