From the course: Object-Oriented Programming with Java

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

What is an object in Java?

What is an object in Java?

- What is an object? Well an object is like a capsule that contains data and behavior. Objects are instances of classes and a class is like a template, like a blank form from which objects are created. Let's imagine an example class Wizard. An object or an instance of that class might be Gandalf. You take the template class Wizard, then you fill in its data, and then you get the object Gandalf. Now Gandalf is an instance of the class Wizard where the properties or member variables have been filled in specific to him. And he exists in a space in memory allocated for a wizard. So an object is a combination of two things: The state of the object, stored as member variables, and a set of methods that give the object the power to do certain tasks. You may have guessed that objects are the foundation of object-oriented programming, and Java. The reason they were created was to make programming feel intuitive, to mirror how…

Contents