Inner Class

An Inner Class is a Class that is declared entirely within the body of another class or interface. An inner class cannot be instantiated without being bound to a top-level class.

Python Example

For more Python class related examples, see:

# Define a class containing an inner class.
class Car:
 
    # Define the class constructor.
    def __init__(self): 
        self.name = 'Automobile'
        self.model = self.Model() 
        
    # Define a method to display the car name.  
    def car_display(self): 
        print('NAME = ', self.name) 
        
    # Define an inner class. 
    class Model: 
        # Define the class constructor.
        def __init__(self): 
            self.name = "Ford"
            self.type = "Sedan"
        
        # Define a method to display the model details.
        def model_display(self): 
            print(self.name, self.type) 
            

# Create and use a Car object.
car = Car() 
car.car_display() 

# Use a Model object. 
car.model.model_display()