Anita Woodford

CSE 210 | Programming with Classes

Week 4 Study Materials

  • Week 4 Notes
  •                 
                        # Creates class Car
                        class Car:
                        
                            # create class attributes
                            name = "c200"
                            make = "mercedez"
                            model = 2008
                        
                            # create class methods
                            def start(self):
                                print ("Engine started")
                        
                            def stop(self):
                                print ("Engine switched off")
                    
                  

    Review Questions

  • Team Work
  • Questions:

    defining a class

                
                    class ClassName:
                
            

    Syntax for attribute

                
                    # create class attributes
                        name = "c200"
                        make = "mercedez"
                        model = 2008
                
            

    syntax for defining a method

                
                    # create class methods
                        def start(self):
                            print ("Engine started")
    
                            def stop(self):
                            print ("Engine switched off")        
                
            

    create an object

                
                    # # create new instance rect1 and rect2 or objects
                    # rect1 = Rectangle()
                    # rect2 = Rectangle()
                
            

    Invoke a method

                
                    expr.methodname(additional parameter values)