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
- Classes of JSP API
- PHP | Classes
- How to specify the order of classes in CSS ?
- jQuery | Get and Set CSS Classes
- Classes in TypeScript
- CSS | Pseudo-classes
- Abstract Classes in PHP
- How to create static classes in PHP ?
- Wildcard Selectors (*, ^ and $) in CSS for classes
- How order of classes work in CSS ?
- PHP | Predefined classes and Interfaces
- How to apply two CSS classes to a single element ?
- How to Add and Remove multiple classes in jQuery ?
- 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.