The difference between class as a function and function is that we make use of this keyword in a function definition that makes it work as a class. Now, an inner class is defined in a similar way.
As you can see in this code, we have created an OuterClass and InnerClass in it just the same way as we did before. But, to access the properties of the outer class we need to have the address of the object. And that is the only right way to do it. As you can see in the example above, in order to access the property x of OuterClass we have used the variable objOuterClass (which stores the address of the current instance of the class) and using that address of object we can easily access any property or method of the outer class in the inner class.
Now, the same trick can be applied while trying to access the members or properties of the inner class. As you can see, we have created an inner class object outside the inner class. So every time the object of Outer Class is created we are creating the object of inner class ad storing its address in the variable innerObj.
Inner class Property z:10
- PHP break (Single and Nested Loops)
- ES6 | Classes
- PHP | Classes
- Classes of JSP API
- How to specify the order of classes in CSS ?
- CSS | Pseudo-classes
- Abstract Classes in PHP
- Classes in TypeScript
- jQuery | Get and Set CSS Classes
- How to create static classes in PHP ?
- How order of classes work in CSS ?
- Wildcard Selectors (*, ^ and $) in CSS for classes
- PHP | Predefined classes and Interfaces
- Use of :even and :odd pseudo-classes with list items in CSS
- How to apply two CSS classes to a single element ?
- jQuery | multiple classes Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.