Using a simple class as an example i wanted too see if i could figure out how to load a class at runtime and create an instance of it to invoke any of it's methods. Almost like using the LoadFrom() or Load() methods contained in the System.Reflection.Assembly class in Visual Basic.Net. I looked in my java docs under the java.lang.System class and found the load() method but all of the docs refer to is loading a library for native method use.
So how do i modify the Example class to load and create a new instance of the Square class once the Square class is taken out of the current .java file of course.![]()
Code:class Square{ public double squareRoot(double d){ return Math.sqrt(d); } } public class Example{ public static void main(String[] args){ Square s = new Square(); System.out.println(s.squareRoot(25.0)); } }




Reply With Quote