这为什么都不行

wangwei0008 2007-08-22 03:26:49
1
class a
{
a A=new a();
a() {
}
void c() {
}
}
class b
{
a B;
void f()
{ B.c();
}
public static void main(String[] args)

{ b test = new b();//这是初始创建的对象
b n; //
n.f(); //这样为什么不行
}
}
2
class a
{
a A=new a();
a() {
}
void c() {
}
}
class b
{
void f()
{ a B; //这样也不行
B.c();
}
public static void main(String[] args)

{ b = new b();
test.f();
}
}
3
class a
{
a() {
}
void c() {
}
}
class b
{
void f()
{ a A=new a();
a B; //这样还不行
B.c();
}
public static void main(String[] args)

{ b = new b();
test.f();
}
}
反正以上都是报错
只有把a 的引用放到所有的方法之外 非静态的方法才能用对象的引用去调用方法
在静态的方法中还不能建立个引用去调用方法 只能是用 创建的对象去调用这又是为什么?为什么非静态的就能用引用去调用方法呢?而且引用一定要在个方法之外呢?
...全文
117 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangwei0008 2007-08-22
  • 打赏
  • 举报
回复
这是问题不是刷屏 求解
zdjray 2007-08-22
  • 打赏
  • 举报
回复
你刷屏么?
frank3G 2007-08-22
  • 打赏
  • 举报
回复
好多 眼睛花了 UP

62,623

社区成员

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

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