File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Instantiating an Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Instantiating an Object" Watch "Instantiating an Object" New topic

Instantiating an Object

Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
How do you instantiate an object??
Could somebody please kindly give me some basic examples. Thank You Very Much!
Donald R. Cossitt
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
There is an excellent tutorial here. and deeper in the same tutorial
[ April 18, 2003: Message edited by: Donald R. Cossitt ]

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
To instantiate an object, simply declare a reference and use the new keyword to create an instance for that reference:

Here I assume that you have already written the declaration for MyClass. It must include a constructor that takes no arguments. If you wish to use a constructor that takes arguments, you put them inside the () as you would with a regular function call.
Since the API already has a lot of classes declared for you, you may wish to instantiate one of them first since you wouldn't have to write all the code for a class that way.

Java API Documentation
The Java Tutorial
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Rupinder
How do you instantiate an object??

If it is not clear,please feel free to ask.

Francis Siu
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
My class is smarter than siu's, it can write chinese with its feet:

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Rupinder
CCNA is about the network application.
Some hardware are developed by CISCO.
Can you point out where Michael instantiate an object in the code?
If you can point out where,I think you can understand the concept of instantiate an object.
Michael is a funny bartender who always help people to answer the question, and the code is funny too,isn't it?
I agree. Here's the link:
subject: Instantiating an Object
It's not a secret anymore!