如何访问在根中的类的方法?见内容

thankyou 2004-05-12 09:46:31
如下
//类Test.java
package test;
public class Test{
public static main(){
}
}

//类RootTest.java
public class RootTest{
public static void f1(){
}
}

那么如何在Test类中访问RootTest类中的方法?RootTest.f1()这种方式编译都不通过。
...全文
13 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
thankyou 2004-05-12
  • 打赏
  • 举报
回复
把RootTest放入包放入包中太麻烦了吧,为什么直接用class就不行?
blasterboy 2004-05-12
  • 打赏
  • 举报
回复
把RootTest放入包中
zgqallan 2004-05-12
  • 打赏
  • 举报
回复
你的Test main方法 没有指定返回类型 当然编不过

//类Test.java
package test;
public class Test{
public static void main(String[] args){
RootTest.f1();
}
}

//类RootTest.java
class RootTest{
public static void f1(){
System.out.println("sssss");
}
}

可以的,f1是静态的
inflames 2004-05-12
  • 打赏
  • 举报
回复
public class Test{
public static main(){
RootTest t=new RootTest();
t.f1();
}
}
就可以了
CuZnRong 2004-05-12
  • 打赏
  • 举报
回复
试试:
public class Test{
public static main(){
Test test = new Test();
RootTest rt = test.new RootTest();
rt.f1();
}
}

//类RootTest.java
public class RootTest{
public void f1(){
}
}
treeroot 2004-05-12
  • 打赏
  • 举报
回复
把RootTest放入包中

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧