Abstraction and Encapsulation
1) Abstraction
and encapsulation are important features of any objectoriented programming
language.
2) Abstraction
involves extracting only the relevant information.
Operator

Description

Example

+

Used to add two numbers

X=Y+Z;
If Y is equal to 20 and Z is equal to 2, X will have the
value 22.



Used to subtract two numbers

X=YZ;
If Y is equal to 20 and Z is equal to 2, X will have the
value 18.

*

Used to multiply two numbers

X=Y*Z;
If Y is equal to 20 and Z is equal to 2, X will have the
value 40.

/

Used to divide one number by another

X=Y/Z;
If Y is equal to 21 and Z is equal to 2, X will have the
value 10.
But, if Y is equal to 21.0 and Z is equal to 2, X will
have the value 10.5.

%

Used to divide two numbers and return the remainder

X=Y%Z;
If Y is equal to 21 and Z is equal to 2, X will contain
the value 1.

Operator

Usage

Description

=

X = 5;

Stores the value 5 in the variable X.

+=

X+=Y;

Same as:
X = X + Y;

=

X=Y;

Same as:
X = X  Y;

*=

X*=Y;

Same as:
X = X * Y;

/=

X/=Y;

Same as:
X = X / Y;

%=

X%=Y;

Same as:
X = X % Y;

Operator

Usage

Description

Example

++

++Operand;
(Preincrement operator)
Or,
Operand++; (Postincrement operator)

Used to increment the value of an operand by 1

Y = ++X;
If the initial value of X is 5, after the execution of the
preceding statement, values of both X and Y will be 6.
Y = X++;
If the initial value of X is 5, after the execution of the
preceding statement, value of X will be 6 and the value of Y will be 5.



Operand;
(Predecrement operator)
Or,
Operand; (Postdecrement)

Used to decrement the value of an operand by 1

Y = X;
If the initial value of X is 5, after the execution of the
preceding statement, values of X and Y will be 4.
Y = X;
If the initial value of X is 5, after the execution of the
preceding statement, value of X will be 4 and the value of Y will be 5.


Usage

Description

Example
(In the following examples, the value of X is assumed to
be 20 and the value of Y is assumed to be 25)

<

expression1 < expression2

Used to check whether expression1 is less than expression2

bool Result;
Result = X < Y;
Result will have the value true.

>

expression1 > expression2

Used to check whether expression1 is greater than
expression2

bool Result;
Result = X > Y;
Result will have the value false.

<=

expression1 <= expression2

Used to check whether expression1 is less than or equal to
expression2

bool Result;
Result = X <= Y;
Result will have the value true.

>=

expression1 >= expression2

Used to check whether expression1 is greater than or equal
to expression2

bool Result;
Result = X >= Y;
Result will have the value false.

==

expression1 == expression2

Used to check whether expression1 is equal to expression2

bool Result;
Result = X == Y;
Result will have the value false.

!=

expression1 != expression2

Used to check whether expression1 is not equal to
expression2

bool Result;
Result = X != Y;
Result will have the value true.



expression1  expression2

Returns true if either expression1 or expression2 or both
of them are true.

bool Result
string str1, str2;
str1 = “Korea”;
str2 = “England”;
Result= ((str1==“Korea”)  (str2== “France”))
Console.WriteLine (Result .ToString());
The message displays True
if either str1 has the value
“Korea” or str2 has the value “France”.

^

expression1 ^ expression2

Returns true if either expression1 or expression2 is true.
It returns false if both expression1 and expression2 are true or if both expression1 and expression2 are false.

bool Result;
string str1, str2;
str1 = “Korea”;
str2= “France”;
Result = (str1== “Korea”) ^ (str2== “France”);
Console.WriteLine (Result .ToString());
The message False is displayed because both the
expressions are true.
