class A has a method a;
class B has a mehtod b;
a want to invoke(调用) b, but b is not static and A can be create with new keyword;
how to solve??????
class B has a mehtod b;
a want to invoke(调用) b, but b is not static and A can be create with new keyword;
how to solve??????
class B has a mehtod b;
a want to invoke(调用) b, but b is not static and B can be create with new keyword;
how to solve??????
public void a(){
// System.out.println("method a");
B b = new B();
b.b();
}
}
class B {
public void b(){
System.out.println("method b");
}
}
public class Test{
public static void main(String [] args){
A a = new A();
a.a();
}
}
a(){
new B().b();
}
应该怎么办?
答:若不允许使用new B();则这道题想考查内部类了,结构如下:class B
{
public void b(){}; class A
{
public void a()
{
b();//不用new B()而直接调用 b()
}
}
}