Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet24/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   20   21   22   23   24   25   26   27   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

instanceof Operator:
Only  object  reference  variables  can  be  used  with  this  operator.  The  objective  of  this
operator  is  to  check  is  an  object  is  an  instance  of  an  exiting  class.  The  syntax  of  this
operator is as follows:
() instanceof()
Sample implementation of this operator and its purpose of use is given below:
public class myTest {
public static void main(String args[]){
int x = 4;
boolean resultant = x instanceof int;
System.out.println( resultant );
}
}
The  output  of  this  code  shall  be  true.  This  operator  can  also  be  used  in  comparison.  A
sample implementation of this is given below:
class Animal {}


public class Monkey extends Animal {
public static void main(String args[]){
Animal newa = new Monkey();
boolean resultant = newa instanceof Monkey;
System.out.println( resultant );
}
}
The output for this code will also be true.

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   20   21   22   23   24   25   26   27   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling