Results 1 to 16 of 16

Thread: Dynamic object creation?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Dynamic object creation?

    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));
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width