Classes

From Rosetta Code
Revision as of 19:43, 27 January 2007 by Adonis (talk | contribs) (→‎[[Python]])
Task
Classes
You are encouraged to solve this task according to the task description, using any language you may know.

The purpose of this task is to create a basic class with a method, a constructor, an instance variable and how to instantiate it.

Python

Interpreter: Python 2.5

 class MyClass:
 
     def someMethod(self):
         """
         Method
         """
         self.variable = 1
 
     def __init__(self):
         """
         Constructor
         """
         self.variable = 0    # Instance variable
 
 myclass = MyClass()