# Classes vs. Objects

It is important to remember that classes are just templates for creating new objects. Objects contain both a state and behavior, and is an instance of a class.

## Instances

An **instance** is a specific version of an object that can differ in numerous ways.

Going back to the previous chapter, ***Rectangle***, ***Animal***, and ***Vehicle*** are all classes. These classes, as is, are considered a type, unless you create a specific version of the class.

In essence, if we create two different vehicles they would be specific instances of the ***Vehicle*** class.

Remember, ***An object is an instance of a class.***

## Examples

```java
public class ExampleClass extends ConsoleProgram
{
  public void run()
  {
    // `Animal` is our class.

    // `myDog` and `myCat` are objects, because
    // they are specific instances of our `Animal` class.
    Animal myDog = new Animal("Cujo", true, 7);
    Animal myCat = new Animal("Kerby", true, 2);
  }
}
```

```
public class ExampleClass extends ConsoleProgram
{
  public void run()
  {
      // `Rectangle` is our class.

      //`mySquare` and `myRectangle` are objects, because
      // they are specific instances of our `Rectangle` class.
      Rectangle mySquare = new Rectangle(20, 20);
      Rextangle myRectangle = new Rectangle(5, 10);
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codehs.gitbook.io/apjava/classes-and-object-oriented-programming/classes-vs-objects.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
