The Artima Developer Community
Sponsored Link

Java Answers Forum
Creating a new instance of a class

2 replies on 1 page. Most recent reply: Apr 24, 2003 5:20 AM by Paul

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Paul

Posts: 2
Nickname: pangbiro
Registered: Apr, 2003

Creating a new instance of a class Posted: Apr 23, 2003 2:30 PM
Reply to this message Reply
Advertisement
ok i want to be able to create new instance of a class as the program is running, only way i can think of doing that is storing the name of instance in an array, but how do i use the contents of array/string as the definition name of an instance of the class?

I am totally stuck with this and am a bit of a novice to java, any help would really be apreciated...

Paul


Jaycee

Posts: 26
Nickname: jaycee
Registered: Apr, 2003

Re: Creating a new instance of a class Posted: Apr 23, 2003 3:44 PM
Reply to this message Reply
Object o = Class.forName("yourclassnamehere").newInstance();

Paul

Posts: 2
Nickname: pangbiro
Registered: Apr, 2003

Re: Creating a new instance of a class Posted: Apr 24, 2003 5:20 AM
Reply to this message Reply
I'm sorry as i said I'm a novice to this could you please break down this block of code.
Thanks for the help

Flat View: This topic has 2 replies on 1 page
Topic: EJb Previous Topic   Next Topic Topic: JDBC IN WINDOWS 98

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use