0

My Scenario is that I need to call the inner class Constructor from another class, Let me know how can I achieve this.

Codes:

public class A {

    // Inner Class
    public class W {

        Integer y;
        String j;
        //Constructor
       W(Integer i, String g){
            this.y = i;
            this.j = j;

        }
    }

How can I access the Constructor W from another class B:

public class B {

    A a = new A();

    a.W.W(10,l);

}

1 Answer 1

4

Just make sure the inner class constructor is public then:

A.W myW = new A.W(10, 1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.