Terminology: Classes and Objects

In this lesson, we will explore the common terms encountered when talking about classes and objects.

We'll cover the following

What we know about objects

We begin this chapter by reviewing some of the earlier material about objects and classes.

  • An object is a construct in a Java program that represents data and performs certain actions. It can represent a real-world object or an abstraction, such as a name.
  • Objects within a program can act on their own or interact with one another to accomplish a task.
  • Each object has a data type, which is the name of the class to which the object belongs. Thus, an object’s data type is called a class type.
  • A class is like a plan for creating objects. That is, the class C describes the data and methods that are associated with each object of type C. Thus, we must have a class—one that either we write ourselves or is written for us—before we can create objects of the class.
  • When we create or instantiate, an object, space is typically allocated for the data that the class describes. The process of creating the object is called instantiation. Thus, an object is also known as an instance of the class type.

Methods

The actions, or behaviors, of an object, are the result of executing the methods that the class defines.

  • We call or invoke, a method to execute it.
  • We do not need to know how to write a class in Java to be able to use one. If someone else writes a class and describes how to call its methods, we will be able to use the methods in our program.
  • Although we will learn how to write our own classes, it is not unusual to use classes that someone else has written. We have mentioned that Java comes with an extensive collection of such classes called the Java Class Library, sometimes called the Java Application Programming Interface or API.
  • The class Scanner that we saw in the chapter A First Look at Java and the class Math that we saw in the chapter Arithmetic Expressions belong to this library. The objects that we discuss in this chapter also belong to classes in the Java Class Library.

Get hands-on with 1400+ tech skills courses.