plain text version:hellouniverse.csp



  1| package hellouniverse; 
  2| 
  3| class hello 
  4| {
  5|     var         greeting;   // instance-level variable a.k.a. field

  6|     static var  said = 0;   // class-level (static) variable

  7|     
  8|     function hello ( who )  // constructor function 

  9|     {                       // name equals to the name of the class

 10|         greeting = who;     // assigning value to the field

 11|     }
 12|     function say ()         // instance-level function a.k.a. method 

 13|     { 
 14|         std::out.printf("%d. Hello %s!\n", said, greeting);
 15|                             // std::out is an instance of class std::stream  

 16|                             // (package std, variable out) 

 17|       
 18|         ++said;             // incrementing static class variable,

 19|                             // this variable will be shared among 

 20|     }                       // all instances of the class

 21| }
 22| function main()
 23| {
 24|     var hi = new hello("World");
 25|     hi.say();
 26| 
 27|     hi.greeting = "Universe";
 28|     hi.say();
 29| }