dimanche 21 décembre 2014

Reflection (Java) - create the class object


class Start
{
public static void main( String[] argv )
{
int argc =argv.length;
if ( argc == 0 ) {
System.err.println( "error");
return;
}

try
{
Class<?> c = Class.forName( argv[argv.length-1] );
//c kowalski = c.newInstance( );
}
catch ( Exception e ) { System.out.println(e) ; return; }
}
}
class Test implements InfoInterface
{
public void display()
{
System.out.println("HI!");
}
static int w;
public int dodawanie (int a, int b)
{
w=a+b;
return w;
}
}


**Hi, My problem is how to create the object of Test class in Start class? The Test class have to be add by commend line. In this program i have to get methods from Test class via object in Start class.


Some advice would be very hopeful. Thanks**






Aucun commentaire:

Enregistrer un commentaire