HOW TO CREATE AN OBJECT OF THE CLASS WITHOUT USING NEW OPERATOR
THE ANSWER IS GIVEN IN THE COMMENTS
JAVA CODE QUESTION
Posted by gautam at Friday, August 03, 2007
Subscribe to:
Post Comments (Atom)
HOW TO CREATE AN OBJECT OF THE CLASS WITHOUT USING NEW OPERATOR
THE ANSWER IS GIVEN IN THE COMMENTS
Posted by gautam at Friday, August 03, 2007
1 comments:
HERE IS THE ANSWER
class A {
int i=10;
}
public class Demo1 {
public static void main(String str[]) {
try {
Class c=Class.forName("A");//Returns the Class object associated with the class with the given string name
Object o=c.newInstance();//Creates a new instance of the class represented by this Class object.
A a=(A) o;//casting
System.out.println(a.i);
}
catch(Exception e){
System.out.println("Exception"+e);
}
}
}
Post a Comment