3

How can i create a instance of the following Class and access its methods. Example:

public class A {
    public static class B {
        public static class C {
            public static class D {
                public static class E {
                    public void methodA() {}
                    public void methodB(){}
                }
            }
        }
    }
}
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Leonardo
  • 431
  • 1
  • 4
  • 7
  • `A.B.C.D.E e = new A.B.C.D.E();` not sure what "How" means. – khachik Jun 10 '17 at 13:00
  • 3
    *FYI:* A class declared inside another class is called a *nested* class. If it is non-static, it is also called an *inner* class. Since your classes are `static`, they are generally called *static nested classes*. They are definitely not *inner* classes. JLS [§8.1.3. Inner Classes and Enclosing Instances](https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.1.3): *An inner class is a nested class that is not explicitly or implicitly declared `static`.* – Andreas Jun 10 '17 at 13:18
  • OP, have you looked this up in the Java documentation? The JLS answers this question. FYI, the documentation for things, like, oh, the Java language for example, is very useful. – Lew Bloch Jun 10 '17 at 15:34

1 Answers1

3

You can use :

A.B.C.D.E e = new A.B.C.D.E();//create an instance of class E
e.methodA();//call methodA 
e.methodB();//call methodB

Or like @Andreas mention in comment you can use import A.B.C.D.E;, so if your class is in another packager then you can call your class using name_of_package.A.B.C.D.E like this:

import com.test.A.B.C.D.E;
//     ^^^^^^^^------------------------name of package

public class Test {

    public static void main(String[] args) {
        E e = new E();
        e.methodA();
        e.methodB();
    }
}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140