How to load a class programmatically?



How to load a class programmatically?..

Answer / madhu

public class MainClass {

public static void main(String[] args){

ClassLoader classLoader = MainClass.class.getClassLoader();

try {
Class aClass = classLoader.loadClass("com.tech.MyClass");
System.out.println("aClass.getName() = " + aClass.getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

}

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

What does persist mean in java?

0 Answers  


can a program use more than one command-line argument?

0 Answers  


Do I really have to type in the programs in the book to try them out?

0 Answers  


What is the java api?

0 Answers  


I am trying to create a new universal user group. Why can't i? : java security

0 Answers  






What is the difference between ec2 and lambda?

0 Answers  


How long can a lambda function run?

0 Answers  


Do I need to install jre if I have jdk?

0 Answers  


What is stateless object in java?

0 Answers  


What is the use of servlet in java?

0 Answers  


Is java installed on windows 10?

0 Answers  


how can program polindrome using java

1 Answers  


Categories