Basic HTML version of Foils prepared 18 May 97

Foil 14 Determining and Testing Class of Object

From Java Tutorial - Spring 1997 Part 4: Multithreading, useful Java classes, I/O, Networking, and the future Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


Suppose an object is called obj , then we get Class of obj by
Class itsclass = obj.getClass(); // and the name of this class by:
String name = itsclass.getName();
One can also use instanceof in following fashion
"foo" instanceof String // is evaluated to true but
mPoint pt = new mPoint(x,y);
pt instanceof String // is evaluated to false



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Thu Jan 8 1998