java动态调用类
package tf;
public class TestPack {
public static void main(String [] args)
{
try
{
IAnimal cAnimal = new bird();
cAnimal.shout();
IAnimal animal =(IAnimal)java.lang.Class.forName("tf.bird").newInstance();
animal.shout();
}
catch (Exception e) {
// TODO: handle exception
}
}
}
//tf.bird 加上包名
//bird.java
package tf;
public class bird implements IAnimal{
public void shout()
{
System.out.println("c c jiji ");
}
}
//IAnimal.java
package tf;
public interface IAnimal {
public void shout();
}
c c jiji
c c jiji
相关文档:
Inner classes, also called Nested Classes, are nothing but classes that are defined within other classes. The nesting is a relationship between classes, not objects.
Inner classes have clearly two benefits, name control & access control. In Java, this benefit is not as important because Java pa ......
初探java内存机制_堆和栈
问题的引入:
问题一:
String str1 = "abc";
String str2 = "abc";
System.out.println(str1==str2); //true
问题二:
String str1 =new String ("abc");
String str2 =new String ("abc");
System.out.println(str1==str2); // false
问题三:
String s1 = "ja";
String s2 = "v ......