/** The operator instanceof returns a boolean. It takes as left
  * operand an instance and as right operand the name of a class.
  * Return true iff the object left is instance of the class right. 
  * So the program below will print out "It is a String".
  * In general given an instance we can determine the class it is
  * an instance of with the getClass method.
  */

import java.io.*;
import java.util.*;

public class InstanceOf {
   public static void main (String[] args) {
	String s = "roses";
	Object a = s;
	Object b = new ArrayList();
	if (a instanceof String)
		System.out.println("It is a String");
	if (b instanceof String)
		System.out.println("It is a String");
	else if (b instanceof Vector)
		System.out.println("It is a Vector");
	else {
        	Class x = b.getClass();
        	System.out.println("The class of b is " + x.getName());
	}
	System.exit(0);
   }
}
/* The output of this program is:
It is a String
The class of b is java.util.ArrayList
 */
