• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does newInstance() method does? Can we create an instance like using new keyword?  RSS feed

 
Vishal Srivastav
Ranch Hand
Posts: 47
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you use the new keyword, if you don't know what you will be instantiating at compile time?

Henry
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!