Classes: Difference between revisions

From Rosetta Code
Content added Content deleted
(New programming task)
 
Line 5: Line 5:
==[[Python]]==
==[[Python]]==
[[Category:Python]]
[[Category:Python]]

'''Interpreter:''' [[Python]] 2.5


class MyClass:
class MyClass:

Revision as of 19:43, 27 January 2007

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()