0% found this document useful (0 votes)
38 views3 pages

Overloading: Method Overloading Operator Overloading

Operator overloading allows operators like + and == to have different behaviors depending on the types of values they are used on. For example, + performs addition when used on numbers but concatenation when used on strings. It is implemented by defining static methods for each operator that specify the expected parameter types. This allows behaviors like adding two strings together or comparing two strings for equality.

Uploaded by

bhanu455
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
38 views3 pages

Overloading: Method Overloading Operator Overloading

Operator overloading allows operators like + and == to have different behaviors depending on the types of values they are used on. For example, + performs addition when used on numbers but concatenation when used on strings. It is implemented by defining static methods for each operator that specify the expected parameter types. This allows behaviors like adding two strings together or comparing two strings for equality.

Uploaded by

bhanu455
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 3

Overloading

METHOD OVERLOADING

OPERATOR OVERLOADING
Operator Overloading
 Operator overloading is also an approach defining multiple behaviours to an operator and
those behaviours will vary based on the operand types between which the operator is used .
 For example + is an addition operator when used between 2 numeric operands and it is an
concatenation operator when used between 2 string operands
Number + NumberAddition
String + String Concatenation
A. Public static string operator +(string a, string b);
B. Public static int operator +(int a,int b)
C. Public static bool operator ==(string a, string b)
D. Public static bool operator !=(string a, string b)
String s1=“hi”;
String s2=“hello”;
String s3=s1+s2;
Bool b1=s1==s2; Bool b2=s1!=s2;

You might also like