| Author |
What does newInstance() method does? Can we create an instance like using new keyword?
|
Vishal Srivastav
Ranch Hand
Joined: Nov 29, 2008
Posts: 46
|
|
Hi friends,
What is the use of method in the class ? Can we create a new instance like we do using keyword? Please help friends and reply as soon as possible.
Thank you all.
|
Vishal Srivastava, Software Engineer (Android), Paradigm Creatives
SCJP 5, SCWCD 5 - http://in.linkedin.com/in/srivastavavishal
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
How do you use the new keyword, if you don't know what you will be instantiating at compile time?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
Find the file called src.zip in your Java installation folder, unzip it, find the Class file (java-->lang-->Class.java), and you can read it for yourself.
|
 |
Mark Barrett
Greenhorn
Joined: May 25, 2009
Posts: 12
|
|
The javadoc for the Class class explains :java.lang.Class
It basically returns a new instance of the class that the Class object represents.
For example:
is the same as
Although you wouldn't use it as a replacement for the new operator. A popular use is in dynamically instantiating a class when the type of that class is not known until runtime.
|
SCJP: 81%
|
 |
 |
|
|
subject: What does newInstance() method does? Can we create an instance like using new keyword?
|
|
|