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

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();
Define an abstract class. Explain its purpose
Define an abstract class - A class with one of more abstract methods is called an Abstract class...
What is the difference between an Abstract class and Interface?
Abstract class and Interface - An abstract class can have both abstract and concrete methods whereas an interface can have only method signatures...
What is singleton class? Where is it used?
What is singleton class? - A class is defined as singleton class, if and only if it can create only one object...
Post your comment