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 is the difference between Logical Parallelism and Physical Parallelism?

0 Answers   HCL,


What is the current code for the Java 5 code class Root { ?

3 Answers  


Do I need jdk or jre?

0 Answers  


What's the difference between code-based security and role-based security? Which one is better? : java security

0 Answers  


What is the difference between jar and executable jar?

0 Answers  






Are jvm’s platform independent?

0 Answers  


How do I open my java console?

0 Answers  


What is dao in java?

0 Answers  


What is property file in java?

0 Answers  


What is stateless object in java?

0 Answers  


What is setstring method in java?

0 Answers  


there are 67 seats in train . there are only 5 seats in a row and in last row there are only 2 seats. One person can reseve only 5 seat at a time. If person reserving seat , the care is atken that he may get all in row. if seats are not available in row then the arrangement is so that person group get nearby seats. the following class is given public class seat { char name; int seat; boolean isSeatempty } 1.Draw require class digram and object diagram. 2.Write function seatallot(int noofperson) to allocate seat with seat nuber printed for the each name.

0 Answers   Sapient,


Categories