Volume of nested classes

If I have a nested class, does any of the owner class exist in its own class?

eg:

public class OwningClass 
{

    int randomVariable = 1;

    public void MakingMethod()
    {
        OwnedClass owned = new OwnedClass();
        owned.SomeMethod();
    }

    private class OwnedClass
    {
        public void SomeMethod()
        {
            // Is anything from OwningClass available here?
        }

    }

}
+3
source share
3 answers

Something “static” from the owner class is available in your nested class.

If you have an instance of the owner class in some method of the inner class, you can also access its private members.

+6
source

The only thing the nested class changes with respect to this parent class is accessibility. A nested class can access private members of the containing type.

+3
source

OwningClass constuctor OwnedClass SomeMethod of OwnedClass.

!

+1
source

Source: https://habr.com/ru/post/1748417/


All Articles