Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java inner classes method access

Tags:

java

I have an outer class. I also have a private inner class that extends JPanel. This is the design of the code.

public class Outer{
    private class Inner extends JPanel{
        public void doSomeWork(){}
    }

    public Outer(){
        Inner inner = new Inner();
        inner.doSomeWork();
    }

    public static void main(String args[]){
        Outer outer = new Outer();
    }
}

I am not being able to access the doSomeWork() method of the inner class from the outer class. Please help.

like image 778
user1917209 Avatar asked Mar 22 '13 01:03

user1917209


1 Answers

Here is how you make an object of inner and access its variables...

Outer outer = new Outer(); 
Outer.Inner inner = outer.new Inner(); 
inner.doSomeWork();

Example code from Oracle is here...

like image 126
chuthan20 Avatar answered Oct 23 '22 17:10

chuthan20