In This Session, You Will Learn To:: Objectives
In This Session, You Will Learn To:: Objectives
In This Session, You Will Learn To:: Objectives
Using Methods
A method is a set of one or more program statements,
which can be executed by referring to the method name.
To use methods, you need to:
Define methods
Call methods
Defining Methods
Defining a method means declaring the elements of its
structure.
Consider the syntax of defining a method:
<Access specifier> <Return Type> <Method
Name>(Parameter List)
{
Method Body
}
Calling Methods
After defining the method, you can execute it by calling it.
You can call a method by using the name of the method.
The method name is followed by parentheses even if the
method call has no parameters, as shown in the following
example:
MethodName();
Summary
In this session, you learned that:
Abstraction is the process of reducing information content in
order to retain only the relevant information for a particular
purpose.
Encapsulation is the process of hiding all the details of an
object that do not contribute to its essential characteristics.
An access specifier is used to determine whether any other
class or function can access the member variables and
functions of a particular class.
The public access specifier allows a class to expose its
member variables and member functions to other functions
and objects.
The private access specifier allows a class to hide its member
variables and member functions from other class functions and
objects.
Summary (Contd.)
The protected access specifier allows a class to hide its
member variables and member functions from other class
objects and functions, just like the private access specifier
while implementing inheritance.
A method is a set of one or more program statements that can
be executed by referring to the method name.
Defining a method means declaring the elements of its
structure.
The access modifiers that can be used with methods are
public, protected, internal, protected internal, and private.
Parameters allow information to be passed into and out of a
method. When you define a method, you can include a list of
parameters in parentheses.
Summary (Contd.)
Parameters can be passed by using any one of the following
parameters types:
Value
Reference
Output