Download presentation
Presentation is loading. Please wait.
1
Lecture 8: Objects and Classes, cont’d discuss hw2 assign h3 Review the main points of objects/classes This Pass-by-value A new example: our Date class
2
HW2 Key point: main program constructs an array of Number objects Then the main program processes the array, typically several times, printing out all the numbers in bases of the user’s choice There is no array inside the Number class If you were confused on this point you can resubmit for a better grade
3
HW3 Placing queens on a chessboard
4
Classes serve 2 purposes A way of organizing static methods, e.g. the Math class Factories for constructing objects, which can then be processed by calling instance methods
5
This a way of referring to data fields (instance variables) of the object (can be omitted unless there is an ambiguity) a way of calling a constructor from another constructor with a different signature (the only way to do this?) a way of calling an instance method from another instance method (the only way to do this?) Only the first 2 of these are mentioned on p.236 Example: the Player class again
6
Java is a Pass-By-Value Language When a method is called, the values of the actual parameters are passed from the calling method to the called method It is not possible for the called method to pass changes to the actual parameters back to the calling method This applies whether the actual parameter is a primitive type or an object reference HOWEVER, if the actual parameter is an object reference, the called method CAN and often DOES change fields in the object that the reference points to
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.