0

hey guys , i had a problem with classes and objects , i need to get the class name form a text file for example and open an object from that class , is that possible if so how can i do it . the object parameters i can send it according the user inputs.

for example can i say :

String ClassName = "class_name";
then ClassName cn = new ClassName;

i know that the piece of code above sounds insane but i need a way to do it urgently
thanks in advance =)

Edited by masijade: fixed code tags

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

i searched for a tutorials but i didn't find how to open an instance of a class
for example

<code>
String input = "Class";
Class c = input.getClass();
</code>

also i can know every thing about the class's methods and constructor thanks to your hint but i still don't know how to open an instance or an object of that class

0

Using the class Class you can
1. Get an instance of Class from a String containing the name of the desired class and
2. Create an instance of the class defined by that instance of Class.
Details of these 2 methods are in the API doc for Class.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.