In this video we learn about instance fields which are used to represent the state of an object. We introduce instance methods, which are the things that the objects of a class do. Objects do things. They behave with their instance methods. Objects have things. They have their instance fields. We use a Fraction class to demonstrate how we can encapsulate the numerator and denominator and hide them using the private keyword, and then expose them again with getters (or Accessors). We implement an add() method, first as an instance method, then again as a static method that accepts two Fraction parameters. We leverage the toString() method so that the object will print itself nicely. And, we discovered that if you don't add the Fraction class to your project, things don't always work as you expect.
Mr. Stride,Java,North Creek High School,Instance Methods,instance fields,state,
0 Comments