aspose file tools*
The moose likes Beginning Java and the fly likes Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Objects" Watch "Objects" New topic
Author

Objects

Ramesh Pappala
Ranch Hand

Joined: Sep 14, 2005
Posts: 50
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

Joined: Aug 16, 2005
Posts: 14144
    
  18

Besides using the 'new' operator you can create objects using reflection, or by deserializing an object that has been serialized before.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
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


bye, <br />Marco
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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 ]

Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objects