Misconception: Students who first learn object-oriented programming in Python don’t realize they need to explicitly define instance variables in Java because this is done implicitly in Python.

Like(2052 Likes)
  • For example, in the Python code below, numSides is a data attribute (the Python equivalent of an instance variable).
    • numSides does not require it’s own declaration, thus its use in self.numSides is sufficient for it’s existence.

      class Die:

        def setSides(self, sides):
          self.numSides = sides

More about this tip

External Source

Interview with Dave Musicant.