WEEK 2 - OBJECT ORIENTED JAVA PROGRAMS AND ARRAYS REVIEW Flashcards
What are programs made of?
Objects
What defines objects?
Classes
What is a class?
A class defines what objects look like and are things implemented during the design time.
They are defined through:
- Using the class keyword
- All Java code consists of classes
- All Java code is “part of” some class
- Big programs can have many classes
- Think of a class as a recipe to create objects
When are objects created and what defines them?
Objects are created from classes at run time.
What defines an object?
- Each object’s properties are defined by the class it was created from
- Many objects can be made from one class
What is in a class?
Information or data (what the objects will be made of) and functionality (what the object will do)
- The elements of a class that contain information (data) are called variables. The variables defined for the whole class are called fields.
- The elements of a class that execute commands to implement functionality are called methods.
What is the syntax for a field variable?
<visibility> <type> <name>;
* Visibility modifier is optional
</name></type></visibility>
How to declare a field variable and initialize it in a combined statement
<visibility> <type> <name> = <value>;
</value></name></type></visibility>
What is the automatically initialized value given to field variables?
Integer, floating point and char = 0 or 0.0.
Boolean = false.
String and any class = null.
What are user-defined types?
User-defined types can be predefined by the class libraries that are provided by the Java runtime. Classes are user-defined types.
What is the . (dot) operator?
An accessibility operator used to access an element that is defined inside an object you must use the object variable followed by the . (dot) operator.
What are attributes?
Information in field variables.
Example.
public class Circle {
private double radius = 10.0;
}
An object is made of ________?
Fields.
What are fields?
Variables declared directly in the class definition block (not in a method).
Create an example of a method
public void methodName() {
}
Create an example of a method with one parameter
public void methodName(dataType paraName) {
}