Junior — Middle
How is an instance of a class created in your programming language?
sobes.tech AI
Answer from AI
In Java, an instance of a class is created using the new operator, which calls the class constructor and allocates memory for the object.
Example:
public class Person {
private String name;
public Person(String name) {
this.name = name;
}
}
// Creating an instance
Person person = new Person("Ivan");
Objects can also be created through reflection or factory methods, but the basic way is new.