Home > Java > javaTutorial > What is the access method of Java internal classes?

What is the access method of Java internal classes?

PHPz
Release: 2023-04-21 15:34:36
forward
1235 people have browsed it

Explanation

1. When an object of an outer class creates an object of an inner class, the object of the inner class must secretly capture a reference to the object of the outer class.

2. When accessing members of an external category, use this reference to select members of the external category. Of course, these editors already help us with that.

In addition, please note that internal classes are only a compilation phenomenon and have nothing to do with the virtual machine. The compiler compiles the inner class into a regular file with outer class name $ inner class name, and the virtual machine knows nothing about it.

Example

class MainActivity extends AppCompatActivity{
    ....
    private List<Fragment> fragments = new ArrayList();
    
    private class BottomPagerAdapter extends FragmentPagerAdapter{
        ....
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }
        ...
    }
    ...
}
Copy after login

The above is the detailed content of What is the access method of Java internal classes?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template