As we know that creation of an object in java is a cost-effective affair. Therefore we should have knowledge of different ways to create Objects in java so that we can use a particular way in the given scenario to handle the situation in a better way. Here we will find out 5 ways to create an object in Java. Using new keyword : This way of creating object in Java is the most common way in all. Using newInstance() method of class 'Class' : You must be aware of the Reflection API in Java. However, under reflection API we have these classes 'Class' & 'Constructor'. Moreover, both classes have newInstance() method in it to create objects in Java. Therefore, we will see newInstance()
You are here
Home > Posts tagged "multiple ways to create object in Java"