public class test{
class A{
void fA(){
System.out.println("we are students");
}
}
public static void main(String args[]){
System.out.println("Hello, 欢迎学习JAVA");
A a=new test().new A(); //使用内部类
a.fA();
}
}
方法2: fA()方法设为静态方法。 当主类加载到内存,fA()分配了入口地址。
public class test{
static void fA(){
System.out.println("we are students");
}
public static void main(String args[]){
System.out.println("Hello, 欢迎学习JAVA");
fA(); //使用静态方法
}
}
方法3: class A与 主类并列
public class test{
public static void main(String args[]){
System.out.println("Hello, 欢迎学习JAVA");
A a=new A(); //使用内部类
a.fA();
}
}
class A{
void fA(){
System.out.println("we are students");
}
}