Lecture 8: Objects and Classes, cont - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Lecture 8: Objects and Classes, cont

Description:

Then the main program processes the array, typically several times, printing out ... If you were confused on this point you can resubmit for a better grade. HW3 ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 7
Provided by: michael1418
Learn more at: https://cs.nyu.edu
Category:

less

Transcript and Presenter's Notes

Title: Lecture 8: Objects and Classes, cont


1
Lecture 8 Objects and Classes, contd
  • 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 users 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
Write a Comment
User Comments (0)
About PowerShow.com