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 classclass Employee {int id;String firstName;String lastName;char middleInitial;float years;}// Creating five different objects from the Employee classEmployee 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
.