Java Objects
An Object is an instance of a class created to access its data and operations
Each object hold its own state
It represents a specific entity created from the class template.
State:Value stored in fields
Behavior:Actions defined through methods
Identity:Distinguishes one object from another
Object Instantiation
Creating an object is known as instantiation .all instances of a class share structure and behavior while storing different state values
public class Object {
static String name = "Raja";
static int no = 90;
String product_name;
int age;
public static void main(String [] args){
Object product = new Object();
Object product1 = new Object();
product.product_name = "Akilan";
product1.product_name = "Alagu";
product.age = 22;
product.age = 21;
System.out.println(product.product_name);
System.out.println(product1.product_name);
System.out.println(product.age);
System.out.println(product1.age);
System.out.println(Object.name);
System.out.println(Object.no);
}
}
Output:
Akilan
Alagu
21
0
Raja
90

Top comments (0)