<p>Objects are known for having characteristics. A car has on average 4 wheels, 2-4 doors, a steering wheel.</p>
<p>Objects can perform actions. A car can drive, hold cargo, and honk.</p>
<h2>In the Programming World...</h2>
<p>Object-Oriented Programming</p>
<ul>
<li>Focuses on objects</li>
<li>Are not linear</li>
<li>Adds organization to a program</li>
<li>Fits with human cognition (making abstractions)</li>
</ul>
<h2>Class Structure</h2>
<pre><codeclass="language-java">public class Classname {
// Fields
// Constructors
// Methods
}</code></pre>
<h2>Fields</h2>
<p>Fields are instance variables, they store values, help define state, and exist in memory for the lifetime of the object.</p>
<pre><codeclass="language-java">public class Car {
private double price;
private double gas;
}</code></pre>
<h2>Constructor</h2>
<p>We can build an object through a constructor. It is a special kind of method, this method requires that you not have a return type and that you name it the same as the class itself.</p>
<p>Constructors help set default field values for the different properties of our class.</p>
<pre><codeclass="language-java">public class Car {
// Begin Constructor
public Car(double cost) {
this.price = cost;
this.gas = 0;
}
// End Constructor
private double price;
private double gas;
}</code></pre>
<p><strong>Note:</strong> The <code>this</code> keyword refers to the object's fields. This helps keep it separate from other variables you can create in the method and the input parameters you receive.</p>
<h2>Accessor Method - "Getter"</h2>
<p>We like to classify methods into two types, accessors and mutators.</p>
<p>Getter methods return a copy of an instance field. It does not change the state of the object.</p>