Explain how to create instance of a class by giving an example.
Java supports 3 ways of creating instances.
- By using new operator
Example :
Product prodMouse = new Product();
- By using Class.forName(classname).newInstance() method
Example :
Class.forName(Product).newInstance();
- By using clone() method
Example :
Object copy = obj.clone();