CH 2 Operatores
CH 2 Operatores
2 ARTHIMATIC OPERATORES:
> if we apply any operator bw 2 var's a and b then result type is always max
int+int=int
byte+byte=int
byte+short=int
short+short=int
int+long=long
long+float=float
float+double=double
char+char=int ex sop('a'+'b'); // 195
char + int=int ex sop('a'+'1'); // 198
char + double=double ex: sop('a'+1.1); // 98.1
Note:[NAN- NOT A NUMBER] in case of float and double if result is undefined then
its hold by NAN.
0/0.0 , 10/0.0
INSTANCEOF: OPERATOR
---------------------
>to check the given object is perticular type or not.
r instanceof x
here r is obj ref, x is class/interface
>but there should parent child relation else its errore
Type Cast operators:
====================
1 implict [automatic/upcasting/widdening]:
compiler is resp to do this type cast, its required if we assign low dt to high
dt.
ex byte -> short -> int -> long -> float-> double
|
char
2 explicit [downcasting/narrowing]:
> developer is resp to do this cast, if we assign high dt to low dt using by cast
operator.
NEW OPERATOR:
=============
> used to create an object
ClassNotFoundException:
-----------------------
if dynamically provided class name is not availble at runtime then we get runtime
exception - ClassNotFoundException
ex: Object o = Class.forName("Test").newInstance();
then at runtime if this Test class file not availble so we get
ClassNotFoundException error.
instanceof Vs isInstance();
============================
>instanceof: is a operatore to check whether given object is of perticular type or
not
and type is specified at beginning.
Thread t= new Thread();
sop(t instaneof Runnable); /true