public class A {
public class B {
xxxxxxxxxxxxxxxx
public C( int a, int b, int c ){
XXXXXXXXXXXXXX
}
public void D(){
XXXX
}
}C是一个构造。。D是一个方法。。现在我要在另外个类E里面 调用 B.D 这个方法
开始我没把B这个类放到A里面
我在E里面 直接 B.b1=new B()
然后b1.D 就可以了现在我把B丢在A里面了
在E里面调用的时候 不知道要怎么弄?
实例化 我拿 A.a1=new A()什么的 根本不行。。求助 要怎么在E里面调用到方法D
包括实例化要怎么写
非常感谢 我新手 不懂。。麻烦详细点
public class B {
xxxxxxxxxxxxxxxx
public C( int a, int b, int c ){
XXXXXXXXXXXXXX
}
public void D(){
XXXX
}
}C是一个构造。。D是一个方法。。现在我要在另外个类E里面 调用 B.D 这个方法
开始我没把B这个类放到A里面
我在E里面 直接 B.b1=new B()
然后b1.D 就可以了现在我把B丢在A里面了
在E里面调用的时候 不知道要怎么弄?
实例化 我拿 A.a1=new A()什么的 根本不行。。求助 要怎么在E里面调用到方法D
包括实例化要怎么写
非常感谢 我新手 不懂。。麻烦详细点
解决方案 »
- httpclient 的问题啊~~~~~~~~~~~~~~~~~希望大家能帮助一下啊~~~~~~~~~~~~55555555555555555555555555
- 求教数组
- 关于Swing getContentPane()方法
- 关于一段链表的代码的问题
- JAVA的GUI图形问题
- 类似System.setProperty("file.encoding","gb2312");System.out.println("中国");通过改变"gb2312"能否得到我想要的任意字符集的中国的编
- 1 高分求救!!在线等!!立刻给分! 谢谢
- throws 和throw在抛出异常时有什么区别?????
- 加入package 包名后,为什么运行就会提示出错???
- J++6.0的调试问题(安全异常)??
- java数组赋值的地方报错
- 【高级】如何通过IP地址解析出用户所在地的地址,原理是什么呀!!!
{
public static void main(String[] args)
{
A.B innerB = new A().new B(); innerB.C();
}
}class A
{
public class B
{
public void C()
{
System.out.println("in C");
}
}
}
public class A
{
private B b = new B();
public B getB()
{
return b;
}
}public class E
{
public static void main(String[] args)
{
A a = new A();
//调用B的方法
a.getB().D();
}
}
public class NestedClass {
static class test {
public void show() {
System.out.println("this is a nested class!");
}
} public static void main(String[] args) {
test tt = new NestedClass.test(); // 嵌套类的声明
tt.show(); // 嵌套类的调用
}
}
1. 嵌套的非静态类,这个叫内部类,需要外部类的实例来new内部类
2. 嵌套的是静态类,这个叫通称为嵌套类,不要外部类的实例,就可以new内部类
例子:内部类public class A { public class B { // 嵌套的非静态类,也叫内部类, 需要外部类的实例来创建内部类:A.B b = new A().new B(); public void D()
{
System.out.println("nested B.D()");
}
}
}
嵌套类:public class C {
static public class B { // 嵌套的静态类,通称嵌套类,不需要外部类的实例来创建嵌套类:C.B b = new C.B(); public void D()
{
System.out.println("B.D() nested in C");
}
}
}
测试一下:public class Test { /**
* @param args
*/
public static void main(String[] args) {
//A a = new A(); //先创建外部类
//A.B b = a.new B();
A.B b = new A().new B();// 通过外部类的实例来new嵌套类的实例。与上面的方法等价.
b.D();
//A.B b2 = new A.B(); 嵌套的非静态类必须有外部类的实例,通过外部类的实例来创建。
C.B b3 = new C.B();// 静态的内部类不需要外部类的实例就可以创建
b3.D(); }}
输出:
B.D() inside A
B.D() nested in C