File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to create objects in java! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to create objects in java!" Watch "how to create objects in java!" New topic
Author

how to create objects in java!

arnold akay
Greenhorn

Joined: Oct 27, 2004
Posts: 1
I learned that the way to create objects in java is by using the "new" keyword... but i am confused when my professor told me that "Object dog = new Object()", he told that this is the way to do an instance of a class. What's the object here ... what's the instance of class here? Thank you.
Amit Saini
Ranch Hand

Joined: Oct 20, 2004
Posts: 280
"An object is an instance of a class"
Consider another example

Student amit = new Student()

'Student' is the class
'amit' is a reference variable that points to a new instance of Student
ie. 'amit' is an object of student.

In your example
Object dog = new Object()
In this case, our class is Object and object is dog. Note the difference between Object and object. Object is a real class in Java, superclass of all classes, top of hierarchy. Whereas 'object' with a small o refers to an instance of that class.

Does this help?
Saket Barve
Ranch Hand

Joined: Dec 19, 2002
Posts: 229
Further elaboration on Amit's response...

One class can have several instances (some exceptions but this will do for understanding sake). Thus the relationship can be said to be one to many.

e.g.
Object a = new Object();
Object b = new Object();
Object c = new Object();
Here a, b,c are instances of the same class - Object. Typically, one utilizes a class by creating instances of the same.

The way to look at it would be: you are creating instances of objects.

Regards,
Saket
[ October 28, 2004: Message edited by: Saket Barve ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create objects in java!
 
Similar Threads
object
What is the different between Object and Context ?
object creation in or outside constructor?
Problem understanding static inner classes
Static object