Basic HTML version of Foils prepared 18 May 97

Foil 49 Comments on Casting

From Java Tutorial - Spring 1997 Part II: Java Language and Object-Oriented Concepts Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


1 Casting (type conversion) is supported between types and class types. Syntax:
  • (classname)reference
2 Two forms of casting are possible: widening and narrowing
3 Widening, where the subclass is used as an instance of the superclass, is performed implicitly
4 Narrowing, where the superclass is used as an instance of the subclass, must be performed explicitly
5 Given Parent: Dot -> DrawableDot (Child):
  • Widening: An instance of DrawableDot is used as an instance of Dot
  • Narrowing: An instance of Dot is used as an instance of DrawableDot
6 Casting between sibling classes is a compile-time error

in Table To:


© 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