Chapter 4 - In person class notes Flashcards
What will we learn in this chapter? (what are the topics in Chapter 4)
- class definitions
- instance data
- encapsulation and java modifiers
- method declaration and parameter passing(movement, multiple files and multiple methods)
- constructors
Can a class can have data declarations and method declarations?
Yes. We’re going to have 1 class per file. Data declarations used throughout, and MULTIPLE METHODS.
Does an object have a state and behavior?
The state of the clock is hanging on the wall and shows 5 pm. The behavior of the clock is ticking and changes the state of the clock time.
The data and variables are the state. The method are the behaviors.
Consider how a six-sided die can be an object?
The state is which side is showing up. The behavior is that it can be rolled. Our die class.
What is the mother of all objects in java?
OBJECT and all classes are descendants of that object.
What do descendants do?
They INHERIT (get) everything from the Object super class object.
What’s good about the toSTRING method?
It’s always important to have one. System.Out is always going to call out the toString() method. The return method should always return the STATE of the object which is the return value faceValue of the die.
What do you want to include in the tostring() method?
Everything that you want to print, any variable.
public String toString()
{
return “Face Value of the Die: “ + faceValue + “ It is color “ + color;
}
What does + indicate in the UML (unified model language)?
It indicates the method is PUBLIC.
+ main (args : String[]) : void
variable : object
return type for the method is VOID.
What’s included in the class box of the UML?
class box has a: 1- Class Name 2- Variables (visibility varName : type) 3- Methods (visibility, method name (parameter name type)
+ Die (void) : constructor
+ means it’s Public Name=die, Void = it does not accept parameters, constructor = does not return.
What software will you use to accomplish UML Goals?
DOWNLOAD violet UML editor files> .jar file
under
https://sourceforge.net/projects/violet/
Why do we not use floats that often, and instead use doubles?
Because there are syntax issues with floats.
Why do we always need to be conscious of narrowing conversions, widening and auto-promotion?
Because anything can be made into an object.