Saturday, May 30, 2015

instanceof operator

package OperatorsDemo;

// This operator is used only for object reference variables.  The operator checks whether the object is of a particular
// type(class type or interface type). instanceof operator is wriiten as:

// (Object reference variable ) instanceof  (class/interface type)

public class InstanceOfDemo extends Vehicles{

public static void main(String[] args) {

String name = "Bpn";
boolean result = name instanceof String;
System.out.println("Example one demo: "+result);

//------------------------------------Another ex --------------------------------

Vehicles obj = new InstanceOfDemo();
boolean result2 = obj instanceof Vehicles;
System.out.println("Example two demo: "+result2);

}
}
class Vehicles{}


No comments:

Post a Comment