Class Object
Class Object
1 INTRODUCTION
As discussed in the previous chapters that aJava programis not p0Ssible without a classande cia
encapsulates data members (or variables) and methods (or function). The data member or variable contan
anyvalue like 4, 78, 3.4, B, 'n, "Liril", "madam', "BOOK', etc.
As far as method or function is concerned, in day to day life we heard about funetions, likeBirthday
function, Marmrage funetion, School's annual function, Sport's day function, ete., and you know ver
that each ot the tunction consist
of series ofevents. So, instead of telling each and every event o1 te
ceremony,we simply call it a function. In programming language function is also known as method a
method or function in Java programming contains series of programming statements and commans
pertorm a task or to nnd the solution of a problem. The Java language comprise of many built-in methogs
which can not be changes. However, it allows you to createyour ownfunction byusing any name
5.2 CLASSES IN JAVA
As discussed in the previous chapters that the underlyvingstructure of all Java programs 1 clasc
Anything you wisn represent in a Java program must be encapsulated in class.
to a
Clas8 defines the
classes. These objects use
state and behaviour of objects. The objects can created with the help ot
be
methods to communicate between them.
a new data type, such as int,
The most important thing to understand about a class is that it defines
float etc. Once defined, this class can be used to create objects of this type. Thus, a class is
a
blueprint (or
template) or an object, an object is an instance of a clas_.
and You will often see the two words object and
used interchangeably n this bok.
instance
5.2.1 The general form (or Syntax) of a Class form (or of class definition
A class is declared with the help of class keyword, The general syntax) a
1Sshown below-
class name-of-class
mportant: The terms used within square
(static) data type member-variablel; brackets 'are optiona
static) data_type member-variable2;
of method or statements
I/The body
W/end of method1
method_name2 Lparameter-list or list of variables])
return-type or data type
Important: The return-type or data type may be
IThe body of method or statements void, int, char, foatlete. The data type void is
W/end of method2 non-return type and restare
return types. Te
Concept of return is diseussed later in this chapter
In the above general form, the first line is commonly known as class declaration; and braces of
Class forms class body. Class body contains the declarations for all its variabies and methods. of the
The variables defined in the class are normally known as memberariables (or instance variable
To perform certain task another compound body is defined within the class, simply known as mem
methods (or methods or functions). Collectively, these elements, member variables and methods
are
kinown Consider the following code
members of theclass.
-
as
Example
class Table
double length;
double breadth, height;
In the above example, a class has been defined with the name Table, containing three instance
variables: length, breadth, and height along with data type:
double.
Currently, the class Table contains only variables but no method (or function). According to the
symtax, It 1s okay. But, to run a program successfully one or more methods must be defined within the
class. Refer to chapter 4 to understand how to create/declare object of class. This has already been discussed
in the previous chapters.
Also note that when a class is declared, no memory is allocated to i variables. This i
because a class is only a blueprint.(Memory spaceis allocated.-when objects of a class type are.create
instance
(Refer terehapter 4).
SZ2 Instance Variables, Class Variables and Local Variables
As discussed in previous chapters that every class contains its members ie. member variables and
methods The member variables are used within the methods) to do some task, A classcan contanany/all
of the following variable types supported by Java:
.
Instance
classis Variables:instance
known as Avariable
an
that is created
separately
variable. For example,
for
everyinstance (or object)
class has if a
of the
then there would be three
three instances
(or objects,
copies of instance variables, one for each instance (or object).
In other words, instance variables
belong to an instance (or object) of a class. Another way
o
saying that is instance variables belong to an object, since an object is an instance of a class
Every instance (or object) has it's own coPy of the instance variables.
2. Class (or Static) Variables The data member instance variable which is declared on
or
once-ter a class and all instances (or objects) of the class-wit strare this single copy of the class 1
known as
static or class variable. The 'static' keyword is used to declare a static or class vania
3. Local Variables: The variables declared inside methods
(or compound blocks) are called local variables.
(or functions),
constructors or bioc
The variable will be declared and initiazedwithin the
method and the variable will be
when the method has completed i.e.
destroy
the local variable _cannot be used or executed outside
SCope SCope means the area within the curly braces '
')
Classes and Methods (or Functions
To understand the diiterence between instance
and static variables, consider the
Example
following coae
class Samplel
Memory spu
float f Memory space float f Memory s loat
oat for variable T
for variable 1 JJor variable f
Instance variables Instance variables Instance variables
a and f tor second a and T for third
and f for first
a instance (or object) instance (or object)
instance (or object)
static
with static keyword (for eg.
Note that the word static is a keyword. The variable that begins
becomes a class or static variable.
int count; etc.)
The variables defined within a class
Non-static
are
instance variables because each instance
called
of these variables.
(i.e., objec) ol the class contains its oWn copy body do not
variables are not shown, because the class
Note that in the above example the local 3
and 4, many (almost al) programs/classes comeams
contain any method (or function). In previous chapters variables.
all the variables are local
and inside the meti.d
a metiod tOr function) Variables and Local Variables
5.2.3 Difference between Class Variables, Instance
class variables is; The class o r
As discussed in point the difference
5.2.2, that between instance and of a clas5s
all the different instances(or objects)
copy that
18 shared by
SLatic variables only have one
instance variables a c r o s s
97
Classes and Methods (or Functions)
In the chapters 2, 3 and 4, you have been
using methods (or function) to write a progra
problem, 7his chapter will make you understand various features and applications of meth
hods.
Methoda (or functions) ofa class are declared inside the class body. A class can contain
ofmethods (or functiona as there t no such limitr any
To run or execute the statementa given within the method (or function), the method shoula
or
invoked or executed. A method (or function) may be called or invoked or executed any
numbere
inition A self-contained program structure that contains one or more statements to
specific task is known as a method (or function) OR a Java method is a collection of statement
grouped together to perform an operation or task. tha
A method or function has the following built-in features:
)Method (or function) prototype or Method (or function) declaration
D Method (or funetion) definition
Ti Method (or function) calling or invoking or executing the statements withi
method body
The general form (or syntax) of defining method (or function) is
Optional
Compulsory Compulsory Optional
data tYpes is
l i s t 14
by commas (also known as method signatures). The syntax of of defining parameter
98
F u n c t i o n
Examplel1
Return-type Name of Method List of parameters
or data-type Or function or variables
Modifier
method protoPe
public static void
display (int w, char h, double d) This is
od ystem.out.pnntint w+h + d); /this statement will run when the function 1s invoRE
ition
body
In the above example the details of various terms are as
modifier
Example 4: Method without modifier and Example 5: Method without static
and with parameter (int y)
parameters
public void display (int y)
void dinplay )
System.out.printin( y*4 );
System.out.println 3 +4);
static modifier
Exmple 8: Method with modifier and
with Example 9:
Method without
parameters
and with return type and no
return-type and n o
parameters
public static int display () public int display ()
is int
return 3+4 ; I/function's data type
must. return 3+4 )} function's data type is 'int'
I/so return i8
/s0 return 1s must.
In all the above examples different forms of method (or function) definitions are shown and the
return. The concept of return' is
int' and char' are shown with the keyword
return-typelater data-type
discussed
or
in this chapter. You may use any form for the method (or function) definition as required
In the chapters 3 and 4 various program are shown, where every class contains methods (or functions)
but without parameters. The following complete program makes you understand that how the parameters
Problem 1
Write a
program to create a class Box, with the data members width, height and depth (all in
w, h and d, to initialize them to the
decimals). Define a method void getData( ) along with parameters,
Calculate and print the volume the box.
data members of the class. of
Solution:
class Box
method oxs n
return type ales
ny value. It accepts three parameters of data type double in local varan
his
w. h and d e n nstance variable width, height and width. A new variable'v of douie
data type 15e e e 5 o r e t h e result of the ealeulated volume. The 'v' is a loeal variable as s
the method
declared-inside- getDatat ).
Follow these steps to use this elass in Blued:
1 As described in chapter 2 and 3, create the above class (ie., Box) in a BlueJ project and compileit.
Ater the c o p message"class compiled - No syntax error" appears, then close this
window to cone o n e project windoW, Here, an orange colour box containing the class n a n e
appears a5 snown n ngure B.2. Now, right-click on this elass name and click on the "new 5Ox *
new window as s 0 W n i g u r e 5.3, appears containing a n instance (or object) " b o x l C H c K
red colour box on the bottom left corner of the window as shown in figure 5.4, appears containins
instance o r o o j e c t n a m e b 9 X and class name "Box". Now, right-click on this object name, a n a c
D aEO
BOx)
Cance
Remove
Fig. 5.2: Complied class In this window, right click om icon FIg. S.5: T s winlow i s creattng instance
or oject boxi Jor the cluss "Box
then click "new Boxt)
Bot aPpears
"Box on
box
void getData(doubie w, doubie h, doubie d)
bOxt
Inspec
baxiBoX
bort Bos Remove Fig. 5.4: The red colour area shows the name of
the metliod votd
Fig. 5.5: Select and click On Ceated stance or object "box for the clas "Box
getDataf..
2. After clicking on the method void getData(..), a dialog box "Method Call" will appear on the screen,
of parameters w, h and d. Type the values
as shown in the figure 5.6 which requires the actual values
then click "OK
of your choice a s shown in the figure 5.7,
Blue Method Can
Blue: Method Call Space for the Actual
actual values of values of
od getData(double w, double h, double
void getData(double w, double h, double d)
h. dd
Varnabies W, n, d rariables
. ,, d
boxi.getata ( oub box1.ge Data (12.5
ole h input by
1 Soube
the User,
dovble d 103 double d
click OKU
Cans o Cence
Fig. 5.6: Method call dialog bo requres Fig. 5.7: NMethond call dulog bos conlains actuul
ucTl values of w. h and d as nput input values of w=l2.5, n=5.0 and d=l03
volumel
void getDala(deuitie. o u t i e h, doubie d
O me0
Fig 5.12: The Teminal Wanudonw
inapod t a t n r the finat result
Remove
am
red
the Fig. 5.15: This winado shonws
10
e color D
Fig. 5.13 The windo Fig. 5.14: Right click on o
createo oject
nlees ne
or Lstance
contans class "OFFCE "OFFICE. in the menu new
oFFICET as object
LSTance o t I C E I
to be crealed.
OFFICE shows to create object
the statement.
describes the creation of object in physical form by writing
But, the following concept
15
The (or general torm) to create an ObJect
syntax
);
class_name objectname or variable = new class_name(
Here, elass_name : means the name of the class dehned by-the use
be any
objectname or variable : means the name of the-ebjet-oF-Instance to be created This may
o r any except variable keyword.
name, place, things
ne: is dynamic allocation operator that ereates the obiect and returns a reterence to that object.
special method or funetion ofa class defined by the same n a m e of the clasSS as
onstructor: Awhich initializes the data members ot the class 18 known as a constructor.
Student is declared as
there is a class named
For example, suppose
class Student
int x; double m; char ch; data members or instance variables within the class
Fig. 5.17: 1Defisult values of each instance variahles contained by the otject or mstance ob
Or, you can also write the above statement in two statements, like
this
Method 2
Student obj; / this line declares an object name or instance, like 'obj' here
o b = new Student( ); creates memory to the object 'obj' and runs constructor
The above two lines ofereating object or instance will behave in the memory as per the commer
entioned against each line. The status of the object or instance for the two lines will be as shown in t
figure 5.18:
After Line 1: Student obj; obj mull
= 0 m= 0.0
After Line 2: obj = new Student); obj ch=
Fg S.18: Declarutiom of object or instunce and initialization of euch instance variable with default values
Now, to
Call or inwOKe or access or execute the method/function show ), the given statement 1s
3S21,
showt 4613 This is method/function call
statement. As mentioned earher,
at
Call a method only its name is used WITHOUT data type (void,
9 te but along WITH parameters, if given. See that the values
, 461.5 passes/goes to variables roll no and total marks
spectively and after executing the print statement given within
the method/function body, the output will
be as:
Roll number =3321 Total Marks = 461.5
The method/function show) can also be called or invoked or accessed or executed as:
int x= 3321; double m
=461.5; Ivariables are initialized with the required values
showi x, m *
This is method/funetion call statement. In this
case two
variables and
m are initialized with the required values and these variables are used
wthinthe parentheses "O', then values of variables * passes/goes to
rollno and 'm' passes/goes to total_marks. After executing the print
statement given within the method/funetion body, the output will be as:
instance_variable_name;
Object name data member .
Remember that the dot/period (.) is known as Member operator and used to call the members of
class (method/function or variable) apart from declaring a fractional value.
Let us consider the following example to understand above two concepts
Example
class Student
int num,
t h i s is data member or instance variable
Problem 3 sslae
Write a program to specify a class Rectangle, with the data members length and breadth
decimals). Define a method void showArea ) to compute the area of rectangle and print it. Define
another method void RunMe() to create two objects and initialize each instance variable with differen
values and by calling or invoking the method showArea( ), print the area of rectangle for all the values
Solution:
class Rectangle ldeclaration of class
double length, breadth;,
void showArea()
cdata members or instance/global variables of class
llmethod or function definition to compute area
double are = length * breadth; *are is local variable to store the computed area
System.out.printin"Area of rectangle is = + are );
/end of the function showArea()
void RunMel ) aoil lnew method or function definition to make object or instance
Similarly, oject ob will be initialized with length=7 and breadth-4.5, then again methodruneon
showAreal 15 called or invoked, where all the statements inside the method will run and retlects tner
result on the basis ot values within object/instance 'obj2.
Refer point 5.3 containing various examples. The static methods/functions are called or invoked
either through another static methods /functions or non-static methods/functionsor using the
class name followed by dot ( operalor and method/funcion name r the static method/frunction
is to be invoked/called from a new class)
static void show() you may also write public static void show()
Example 2
static method");
System.out.println( I am a
that of general utility but do not directly affect an instance of that class is usually
Methods are
declared as class methods.) Java class library also contain a large number of class methods. For
example, the Math class defines many static methods to perform mathematical operations. One
this b0oR) 18 Used as: Math.pow(3,4;
of its method named pow() (will be discussed later i n
Note that, before the dot operator we have used the class name (1.e., Math), then dot operator ()
and then its static method name (i.e., pow( )) with the required parameters.
2. Instance Methods: All the methods defined WITHOUT the static keyword are known as instance
methods/fiunctions or object methods/functions or non-static methods/functions
Refer point 5.5 containing various examples. They are called or invoked or executed either through
the object (or instance) of the class (refer example under point 5.5 and problem 3) or by just using
the methodiijunction name
For exampte, all of the methods in earlier solved programs (such as: getData( ), show( ),
showArea( ) and volume) etc.) are nistance methods or object methods or non-static methods.
1//end of class
Class compiled- no syntax errors
Example4:
Example3:
calling o r invokin9
aangoE invoking
1 thod ahow static method show()
Static method
through another class
h anathe class show) is
ietatit tanction deno Static method class Sample4
called through
class Sample3 show) is called
s t a t i c void show()
through static non-staticC
s t a t i c void show() method demo
method demo(. System.out.println("static")
i n a new clas
ytes.Out-pranEIn°staEzC ) in a new class
1 e n d ot c l a s s Sample3
run'
/fend of class Sanple3
run' as:
making another class below Sample.spo
/making another clasa beiow Samples.show. ublic class Run
Sample4 ells
public class run Sample3 tells that method
that method
5tae void demo()/non-sta show 15
ata tic void demO
show) 18 member
member of class
Sample3. show( ) <
Sample4.show) class Sample
| / / e n d off naw class F
Samples. rend Or new class Ran
As shown above in classes "Sample2" and "Sample4" the method/function void demo15 1ar)
static or instance method/function and is calling or invoking static method show(O. S
the non-static or instance methods are invoked.
public statie void main( String argsl y o u may also write Stringl) args
Statements....
function show) which i8 called or invoked from main) method after creating the object (or instanc
and prints the output "non-static function".
As already discussed that the class/static method is invoked directly without any prefix because iti
a class method and can be executed throughout the class, whereas, instance/non-static method cannot h
it the object/instance of the class an
executed directly, though it is the member of class, 50 require
through object
t h e method is called. You may also call or invoke static method function using an instana
object.
Remember that when you right click on the compiled class, the drop down
menu will appear as shown in the figure. Now you have to click on void main
String args[ })" to execute the main() method. This type of menu will always
appear if a class contains standard main( ) method/function.
Open Edlo
Comple
efinition: The list of variables given at the time of method definition along with their data tp
and also at the time of calling or invoking method/function without data type are known as parameters
Example ehar es, int y are the
parameters
void demo char cs, int ý) is function
This is This line prototype
method or M and 287 are the parameters to
function be passed to char cs and int y
definition
d
body demo( M, 267 )- T ' h i s is method/function calling statement
definition body
Actual Parameters: The list
of variables given at
without their data ypes are known as actual
the time of method/function calling (or invorg
Example 1:
parameters (or
arguments).
M and 267 are ACTUAL parameters
demo M, 267 ) oldh
Example 2:
int x =
26 char mn =
"M; variables mn and x are ACTOAL parameters
demo mn, x }
Note that the formal parameters must be variables along with data type of
commas but the dctual parameters may be in the actual values (refer example 1) each
or
variable separatea
in the form of vdrio
bhich must contain some values (refer example 2, here variable x is assigned 267 and mn is assigned
To better understand the concept of actual and formal parameters, consider the following program
Program 4:
Wrte a programto create a class Rectangle, with the data members length and breadth (all in
decimals)., Define a method void Accept(O along with parameters, I and b in decimals), to initialize them
to the data members of the class. Another method void showArea( ), computes and prints the area of
) function to ereate the object/instance of class type and call the functions
rectangle,
Alsodefine a main
to print the area of rectangle.
Solution:
class Rectangle
return t s
Ifunction
void callMel)
In the above example, the arrows indicates the place, where the control is transferring it self.
Remember that the function call statement works in two parts;
at the nst
par", sum(3, 5) activates and
line), then the
the control reaches to first line of method I function definition (means method prototype
to and to n , atter that the control enters into
parameters passed (1.e. value 3 passes/copies
are m '5
executes all the statements (as int s=m+n) and when the control reaches to
methodIfunction body and
return (s); the second part of the method/function call statement gets activated and the return value of
in the method/function calIMel ), which will be printed after that. Note
Swill be received by variable "R' Also
n are tormal parameters.
and
that, here values 3 and 5 are actual parameters whereas m
at the method/function call statement must
remember that the return _data_lype and receiving_data type
be same, otherwise it will give an erTOr
Problem 5:
class Sample, with h e fractionat data members/instance variables A, B
Wnte a
program to create a
and C.
Define a method void Coordinates() along with parameters, X, y and z, to initialize them to the
ormula: X = B. 4AC
create the objectinstance of class type and call the functions
Also definé a main( ) function to to
PInt the result of the relation.
llprinting resul
System.out.printnResult of X
=" + ans ;
W/end of the main( ) function
Mlend of the class
function main() is called:
Output: The following is a computer generated output when
Buet femnawOkea
Optons
values are 7.0 5.0 3.0
he parame ter
Result of X -59.0
=
Problem6:
data member/instance variable radins
Write a program to create a class Circle, with the fractional
to store the value of radius and. Detine a method void accept( double r) to initialize argument T
instance variable 'radius. Another method double computeArea() to calculate and return the area
circle using the formula: Area = T**
Also define a method void ShowOutput) to invoke the functions accept() and computeArea
to print the area of circle.
Solution:
class Circle
14
Classes and Methods (or Func
13
double, so return
double computeArea(0 unction definition data type is
local
double area = 3.141 radius radius; Il variable 'area' is
(
return aea, you may also write return area
main( ) method
that in the program 5,
a
calledinvoked.
below:
Consider one more example programs described
class Example
parameters m andn
definition with formal/local
int display( int m, int n) I/ function
of squares of m and n
sum
Ifinding
n t sum = m m +nn,
Ilreturning sum
return sum,
Vlend of method display()
1/end of class
described below:
to e x e c u t e
the program is
by step process
Output: The step
115
lasses and Methods (or Function3)
Step 3 See the red b0x at the
Step 1 Right cliek Click OK on this window
2
Step
on class to make to make object/instance of cla8s bottom 1elt corner that
contains object "example"
object'instance. examplel" provided by compiler.
Step 6: Alter pressing OK, the Step 5: Now, the given windoW p * ugnt Chick on the
see Lhat ODect ana Belect method
value
(80) appears in the requires parameter values,
return 8, 4 for m and n, then click oA.
int displayl int m, int n).
following window. Clhck on
"close
the job is terminated.
B c Method Resut X Blue Method Call
New Class
nt dplynt a,ntn) nt displaytint m, tnt n)
eapeLdpiay3,
retmed: Get sanple1.6eplaY ( ntm
Commp
ntn
Kample1 nt dsplayint m,
Exanpe
ino)
Cose
Cance Inapect
eramble1Ex Remove
Problem8:
Write a program to define a method/function double Interest( double p_amt, double rate, int
class simplelnterest
double Interestl double p_amt, double rate, int time ) I function definition
double SI = (p_amt * rate " time ) / 100; I/finding simple interest using formula
parameter
values input
leln LInterest150000 daublept ATpleini.interest(1s000.0, 6.25, 5) pet value as
6.25 double rate rebrned: Get
output
by the user nt t e double
%687.5
Cance Cose
116
Classes and Methods (or Function
10 METHOD OVERLOADING (or POLYMORPHISM)
6.10
In simple understanding, the thing/object which is available in many
nle, the object "table" is available in torms i Table. Computer
Table, Dining Table,
Computer
many snapes u8, Study
forms as: 12 incneated by their
LED TV, Internet T
ODJect TV is also differentiated their
TV,
V, LCD all tables urseTV's but they
are or are
sizes and
other specífications. similarly
similarly,
Overloading refers to the use of the same thing/object for different purposes thodlfunction call
appears to pertform diferent activities depending on the kind of data sent to it in the methouu
tatement. 1his 1s ais0 Known as polymorphism in 00P.
Definition: The process of defining two or more methods/functions with the sane ut with
parameters (or arguments) is known method or function overloaaing
different akL DpEs o as
The advantage ot using method/ function overloading is that the program whicn co
concept Other programs because in case of method/function overloaang m
compiler loads all the functions and when they are called or invoked then the compile lem
the basis o paraneters (or arguments) or data types. The method (or function) overloading_ pleea
polyniorph1sm.
48-i67.
Also define a method void RunMe() to the above overloaded methods/runctions
relevant
invoke by passing
parameters/argument and print the results.
Solution
the following program the method/function
uses overloading concept
class OverloadSample
Inote, that there is NO data members in this class
void check( 1st overloaded function
char ch) definítion, ch is formallocal parameter
System.out.print The four characters are ");
System.out.println(ch+" "+(char) ch+1) +" "+ (charX ch+2)+" "+(charX ch+3) ;
W/end of lst method check()
void check( char chl, char ch2) I/2nd overloaded method
definition, chl and ch2 are
formallocal parameter
System.out.println(The previous character of + chl +" is= "+ (-ch1) );
System.out.println( The 2nd previous character of+ch2 + is = "+ (char)( ch2- 2)
Wlend of 2nd method check()
char check(int m)/3rd overloaded function definition, m is formallocal parameter
char st= (char) m; Il convert 'm' into character
form using type casting (Cchar)
return st;
l/returning
the
V/end of 3rd method check)
new character
stored in 'st' after converting m'
118
Classea and Methoda (or Funetion
Output: The rouowing 18 a computer Kenerated result when method RunMel ) 1s caledi
ptmn
The
rour characters are 1g 3
Th pEevkous
ou character of T
chaEACter of
i-
ot
CEer tom 107
i k
In the above prog, nside the method/function RunMe ), three overloaded methoas r
single paraeter, check("T", F)-with tn and check( y )-with single parameter
with t n two parameters
automatically distinguished that which
a compiler
be called/invoked
method is to be thus, ll
called/invoked and thus all the overloaded method/functions successtully execueu
method
Problem 10
Write a program to create a class number and overload method minimum) as follows:
arguments nl
(int minimum(
int nl, int n2):
to return the smallest integer from the
and nz, using the conditionavternary operaor
2
Gi) int minimum( int xl, int x2, int x3): to
the smallest
return using integerfrom the argumenhod
the suitable mathematical
method
and x3,
function.
Also define a method void PrintOut( ) to invoke the above overloaded methods/functions by passing
and print the results.
relevant parameters/argument
Solution:
the following program uses the method/function overloading concept
class number class
Inote, that there is NO data members in this
int minimum( int nl, int n2) I/lst overloaded function definition
intsmall= (nl < n2 )? n l : n2; /indig smallest from nl, n2 using ternary operator
lhreturning smallest number stored in variable 'small
return small;
/end of lst method minimum()
overlonded function definition
int minimum( int xl, int x2, int x3)
'sm
x2 ); /deciding smallest from xl and x2 and store in
int sm= Math.min( x1, deciding smallest from s m and
x3 and store in 'small'
int small = Math.min( sm, x3
variable small'
llreturning smallest number stored in
return small;
Wend of 2nd method minimum(.
l function definition to call overloaded functions
public void PrintOutl)