Basic HTML version of Foils prepared 9 Sept 1997

Foil 30 Comments on Casting

From Java to be used in (Scientific) Computing Part II: Java Language and Object-Oriented Concepts Basic Simulation Track for Computational Science CPS615 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox


Casting (type conversion) is supported between types and class types. Syntax:
  • (classname)reference
Two forms of casting are possible: widening and narrowing
Widening, where the subclass is used as an instance of the superclass, is performed implicitly
Narrowing, where the superclass is used as an instance of the subclass, must be performed explicitly
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
Casting between sibling classes is a compile-time error



© 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 Sun Feb 22 1998