Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Class members Class definitions consist of variable declarations and method definitions, collectively called members of the class. Variables declared.

Similar presentations


Presentation on theme: "1 Class members Class definitions consist of variable declarations and method definitions, collectively called members of the class. Variables declared."— Presentation transcript:

1 1 Class members Class definitions consist of variable declarations and method definitions, collectively called members of the class. Variables declared as members of a class are called instance variables, because each instance of the class has its own (private) copy of each instance variable.

2 Methods accepting information Methods can accept information, via their arguments, in a method call. We have seen this already with the “add” method of the Terrarium: chapter1.Terrarium t = new chapter1.Terrarium(); t.add(new chapter1.Ant()); 2

3 In this example, the add method is being provided a reference to the newly created Ant object. 3

4 Methods returning information Methods can return information, as the value of their method call expressions. We have seen this already with the “start” method of the Ant: chapter1.Terrarium t = new chapter1.Terrarium(); t.add(new chapter1.Ant().start()); 4

5 This example is very similar to the first one, except that the start() method is called on the Ant. What is sent to the add(…) method is the value of the expression new chapter1.Ant().start() The value of this expression is the value returned by the start() method. In this case it is a reference to the Ant object itself. –The only reason we know this is because I know what the start() method does, having written it. 5


Download ppt "1 Class members Class definitions consist of variable declarations and method definitions, collectively called members of the class. Variables declared."

Similar presentations


Ads by Google