Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Im having trouble invoking methods on the objects returned from Classs forName method-how should I use Class.forName?

0
Posted

Im having trouble invoking methods on the objects returned from Classs forName method-how should I use Class.forName?

0

Ans : Invoke newInstance on the Class object returned by forName and then cast the resulting instance to a type that the compiler can access; only then can your program invoke a method on the instance of the newly loaded class. The forName method in class Class is a hidden gem in the Java system. This method lets your code create a new class type from a dynamic name—that is, a name given to your program as a string at run time. What’s particularly powerful about using forName is that neither you nor the compiler needs to know the exact details of the new class, only what superclass it extends or interfaces it implements. The forName method is what enables a Java-capable browser, for instance, to load arbitrary applets, even though the browser can’t know in advance what Applet subclasses it will be called on to create. The forName method takes a String argument as the name of a class, and attempts to create a binary representation for a class with that name. (This process is called clas

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123