Chapter 1 Flashcards
Objects
- Created from classes
- represent “things” from the real world or from some problem domain
- represents individual instances of the class
- ie. if class is car, objects are racecar, limousine etc
Classes
- represents all objects of a kind
- uppercase
- ie. car
Instance
- a particular object
- refer to objects as instances when we want to emphasize that they are of a particular class
- ie. the object is an instance of the class car
Objects naming convention
Lowercase
Objects have___ which can be invoked, and called what in Java?
-operations
-methods
What do methods have to pass additional info needed to execute?
parameters
Data type
specifies what kind of data can be passed to the parameter
-integer (int) specifies whole numbers
An object has attributes which are?
Values stored in fields
The class defines_________ but each object_________
-what fields an object has
-stores its own set of values (the state of the object)
State
-The set of values of all attributes defining an object
-inspect in java
Each class has a source code ___________________
-(java code) associated with it that defines its details (fields and methods)
Compilation
-java is a high level language
-but computers can only interpret low level machine code
-compilers translate programming code into machine code
What return type returns a value?
non-void return type
Signature
-The method name and the parameter types of a method
-it provides the info needed to invoke the method
ie.
void moveHorizontal (int distance)
signature = moveHorizontal(int)
Header
-provides info about the method in question
ie.
void moveHorizontal (int distance)
String type
indicates that a section of text (a word or sentence) is expected.
-always enclosed W/I double quotes.
Multiple instances
Many similar objects can be created from a single class
Fields
Object attributes, when some methods are called the state of the object or attributes changes.
ie. moveLeft changes the xPosition attribute
Boolean
A type that can represent 2 values: true or false
Result
Methods may return info about an object via a return value.
String getName()
string is the return type
Which return type doesn’t return a value
void as in:
void changeName (String replacementName)
What happens when you specify a color that is not known in Java?
it turns black
What happens when you enter a string without the quotes in Java?
Causes an error
ie:
(yellow is entered)
Error: cannot find symbol - variable yellow
Method calling
Objects can communicate by calling each other’s methods