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

explain how java se 8 data and time api solves issues of old java date api?

0 Answers  


why i can not access private variable in other class?

4 Answers  


Can a method be static and synchronized?

0 Answers  


What is flatmap in rxjs?

0 Answers  


What is an action class in java?

0 Answers  


Are streams faster than for loops?

0 Answers  


What is dependency injection in java?

0 Answers  


What happens when the parent process of a child process exits before the child ?

0 Answers   Amazon,


What are the advantages of java sockets?

0 Answers  


What is the means of java?

0 Answers  


Why do we only use the main method to start a program?

0 Answers  


What is the need to declare main() method as static in Java?

12 Answers  


Categories