Objects and Classes in Java
Java applications are called Write Once Run Anywhere
Article By The Techie King
we will learn about Java objects and classes. In object-oriented programming technique, we design a program using objects and classes.
What is an object in Java
An entity that has state and behavior is known as an object e.g., mobile, account, marker, pen, chair, car, etc. It can be physical or logical. The example of an intangible object is the banking system.
Characteristics of object
- State: represents the data (value) of an object
- Behavior: represents the behavior (functionality) of an object such as deposit, withdraw, etc
- Identity: An object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. However, it is used internally by the JVM to identify each object uniquely
Object Definitions
- An object is a real-world entity.
- An object is a runtime entity.
- The object is an entity which has state and behavior.
- The object is an instance of a class.
What is a class in Java
A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical.
A class in Java can contain below
- Fields.
- Methods.
- Constructors.
- Blocks.
- Nested class and interface.
Example of class Bike