Explain how to create instance of a class

Explain how to create instance of a class by giving an example.

Java supports 3 ways of creating instances.

By using new operator
Ex : Product prodMouse = new Product();

By using Class.forName(classname).newInstance() method
Ex: Class.forName(Product).newInstance();

By using clone() method
Ex: Object copy = obj.clone();
What is an abstract class?
What is an abstract class? - A class with one of more abstract methods is called an Abstract class....
Java - Difference between an Abstract class and Interface
Difference between an Abstract class and Interface - An abstract class can have both abstract and concrete methods whereas an interface can have....
What is singleton class? Where is it used?
What is singleton class? Where is it used? - A class is defined as singleton class, if and only if it can create only one object. This class is useful when.....
Post your comment