Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
In how many ways we can create objects in java..?
plz explain .....
Posted
Comments
Sergey Alexandrovich Kryukov 8-Oct-12 1:57am    
The question makes no sense. What do you mean "how many"? How do you want to count "ways"? Why?
--SA

1 solution

How many ways?

There is one way:
Java
Object object = new Object();


Otherwise the Object needs to be given by another part.
One can hand over Objects/Copies of Objects as arguments:
Java
public void method(Object object){
  // doany();
}

But then the Object has been there in the ohter method.

It's sometimes not directly visible where an Object is created and why/how it is coming up.
That's often happening when using a framework. Spring e.g. has a mechanism to "create" Objects by a XML definition.

EDIT: have you read this? Creating Objects - The Java Tutorial[^] @ oracle.com
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900