I want to access one or many classes from an entry point(main) without importing package. For example:
package com.ank.dynamicJarFileCreation;
public class revDemo {
public static int reverseNumber(int n)
{
int rem,rev=0;
while(n>0)
{
rem=n%10;
rev=rev*10 + rem;
n=n/10;
}
return rev;
}
}
above one is revDemo
class and I want to access above reverseNumber(int n)
method from an entry point below. For example:
public class revCall {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
int n=485154;
System.out.println(revDemo.reverseNumber(n));
Or by this way.
Class cls = Class.forName("reverseDemo");
Object obj = cls.newInstance();
System.out.print("Class Name"+cls.getName());
Object obj = null; //It is a object of -> com.ank.dynamicJarFileCreationo
System.out.println(((com.ank.dynamicJarFileCreation)obj).reverseNumber(n));
}
}