I want a method which returns an Object which is given a class depnding on the value of the String that is passed through
public static Object createObject(String classname){
Object myobject = null;
try {
Class myclass = Class.forName(classname);
myobject = myclass.newInstance();
System.out.println(myobject.objectAttribute);
}catch(Exception e){
}
return myobject;
}
I want to then be able to print out an Attribute (e.g objectAttribute) that i know will be held by all possible classes that classname could represent. The possible classes are defined in separate files. But the compiler gives error cannot find symbol objectAttribute. How can i access an atribute of this object?
sorry for poorly worded question
Thanks for any Help