What is Class Instance In Java?
In Java, a class instance is an object created from a class blueprint. When a class is defined, it serves as a template, and an instance contains specific data associated with that class. You create an instance using the new
keyword, which allocates memory for that object. Each instance can have unique properties (instance variables) and behaviors (methods) while sharing the class's structure. For example:
class Dog {
String name;
void bark() { System.out.println("Woof!"); }
}
Dog myDog = new Dog(); // myDog is an instance of Dog