Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 5. Scripting Java with Jess > Working with exceptions - Pg. 70

70 CHAPTER 5 Scripting Java with Jess course, some classes have public member variables, like the x and y members of java.awt.Point , which you'll want to both read and modify. Instance variables are members of a class that belong to individual objects; each object has its own copy of an instance variable. Jess can access public instance vari- ables of Java objects using the get-member and set-member functions. In this exam- ple, a Point object is allocated, and its x and y members are set and then read: Jess> (bind ?pt (new java.awt.Point)) <External-Address:java.awt.Point> Jess> (set-member ?pt x 37) 37 Jess> (set-member ?pt y 42) 42 Jess> (get-member ?pt x) 37 The set-member and get-member functions also work on class variables. There is only a single copy of each class variable, and all objects of a class share it. Class variables are also called static variables in Java. You can access class variables by using the name of the class instead of an object as the first argument to set-