Object

An object is an instance of a class. It contains the properties and functionalities of its class.

When an object is created, memory will be allocated for it.

Object Example in Java

In Java, an object is created using the new keyword. The new keyword tells the compiler to create a new instance of a class and allocate memory for it.

// Creating the Employee class
class Employee {
int id;
String firstName;
String lastName;
char middleInitial;
float years;
}
// Creating five different objects from the Employee class
Employee tina = new Employee();
Employee louise = new Employee();
Employee linda = new Employee();
Employee bob = new Employee();
Employee gene = new Employee();

In the above example, five different objects were created from the class Employee.

Objects in Different Languages

Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn More on Codecademy

Edit this page on GitHub

Contributors