Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects

 
Ramesh Pappala
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please tell me how many ways we can create an object.
And also give me the syntax also.
I know only this way
classname obj=new classname();
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides using the 'new' operator you can create objects using reflection, or by deserializing an object that has been serialized before.
 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a static factory method.
The object you want to create must have a static method that return a new istance of the class. Then you call the method and you will have the new istance
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just by hiding the details in a function call does not mean that the function somehow "magically" creates an object. In the end, all of these ways will ultimately use the new operator, so from my point of view there is only one way to create an object.

Layne
[ September 30, 2005: Message edited by: Layne Lund ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic