Exforsys

Online Training

Defference between new & Class.newInstance()

This is a discussion on Defference between new & Class.newInstance() within the Java Tutorials forums, part of the Articles and Tutorials category; Hi All, I would like to know about what is the difference between \"new\" keyword and Class.newInstance(). ...


Go Back   Exforsys > Articles and Tutorials > Java Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-05-2004, 09:32 AM
Junior Member
 
Join Date: Oct 2004
Posts: 6
ajagania
Defference between new & Class.newInstance()

Hi All,

I would like to know about what is the difference between \"new\" keyword and Class.newInstance().

Any pointers will be greatly appreciated.

Thanks & Regards,

Anant.

Low aim is a crime......
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-13-2005, 05:21 AM
Junior Member
 
Join Date: Jun 2005
Posts: 1
mahens is on a distinguished road
When u use the new operator to create an instance of a class, u cant change the class which is been instatiated. In other words, the class which is instantiated is determined at compile time.


If u use class.newInstance(), then u can change the class which is been instatiated at runtime. In other words for example,

Class c = Class.forName("Some class Name");

Object o = c.newInstance();

Here, u can change the String argument in the class.forName() method and change the class which is getting instatiated. Say u got this String from a property file, then u dont even have to compile the class in order to get another different class instatiated.

whe u use Object o = new SomeObject(), u cant change the class which is getting instatiated without changing and recompiling again

Hope u get my point.

Ask if u have any further queries relating to this

Regards

Mahen
BSc Eng (Comp Sci and Eng), SCJP 1.4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.