Debian Codegraph @

examples/book/digital-artists/chapter9/Listing9.1.ck

raw
1 // Listing 9.1 Making and using your first new class, testData
2
3 // Simple Class to show data access
4 public class testData { // (1) Declares a public class called testData
5 1 => int myInt; // (2) Local int variable
6 0.0 => float myFrac; // (3) Local float variable
7 // a simple function that adds the data
8 fun float sum() { // (4) Function to add the two
9 return myInt + myFrac;
10 }
11 }
12
13 // make one of our new testData objects
14 testData d; // (5) Tests it all by making a testData
15
16 <<< d.myInt, d.myFrac, d.sum() >>>; // (6) Prints out default initial testData values
17
18 // change the data, just like we would variables
19 3 => d.myInt;
20 0.141592 => d.myFrac;
21
22 // check to show that everything changed
23 <<< d.myInt, d.myFrac, d.sum() >>>;