Hello Friends!!!
Today we are going to learn more operators. In one of my previous articles, I have mentioned that Java is rich and powerful in the matter of Operators.
Some Operators such as,
These are more operators available in Java. That's it with the operators in Java. Let's take an example of instanceof operator.
Try this example and check the output.
Today we are going to learn more operators. In one of my previous articles, I have mentioned that Java is rich and powerful in the matter of Operators.
Some Operators such as,
.(Dot)
|
This operator is used as a member access operator.
|
+ | This operator is also used as a string concatenation operator. |
[ ]
|
Square brackets are used to define the size of the operator.
|
instanceof | This operator is used to check the object is defined in the class or not. |
+=
|
Arithmetic addition and assign to the variable, for example, a+=b
|
-= | Arithmetic subtraction and assign to the variable, for example, a-=b |
*=
|
Arithmetic multiplication and assign to the variable, for example,
a*=b
|
/= | Arithmetic division and assign to the variable, for example, a/=b |
%=
|
Arithmetic modules and assign to the variable, for example, a%=b
|
&= | Bitwise AND and assignment |
|=
|
Bitwise OR and assignment
|
^= | Bitwise exclusive OR assignment |
>>=
|
Shift right with assignment
|
>>>= | Shift right zero fill assignment |
<<=
|
Shift left with the assignment
|
These are more operators available in Java. That's it with the operators in Java. Let's take an example of instanceof operator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//wap to demonstrate instanceof | |
class DemoInstance{ | |
public static void main(String args[]) | |
{ | |
DemoInstance d=new DemoInstance(); | |
boolean b=d instanceof DemoInstance; | |
System.out.println("d is an instance of:"+b); | |
} | |
} | |
//In inheritance | |
class Shape{} | |
class Circle extends Shape{ | |
public static void main(String args[]) | |
{ | |
Circle c=new Circle(); | |
boolean b=c instanceof Shape; | |
System.out.println("c is an instance of Shape:"+b); | |
} | |
} |
Try this example and check the output.
No comments:
Post a Comment