constructor overloading like Java ?
Markus Jais
mjais at web.de
Mon May 26 09:20:10 EDT 2003
Karl Scalet wrote:
> Hello Markus,
>
> Markus Jais wrote:
>
>> class MyObject
>> {
>> public MyObject()
>> {
>> System.out.println("uno");
>> }
>> }
>> class MyClass
>> {
>> private int a;
>> private MyObject my;
>>
>> public MyClass(int a)
>> {
>> this.a = a;
>> }
>> public MyClass(MyObject my)
>> {
>> this.my = my;
>> }
>> }
>
> you cannot have more than one contructor, but you could handle
> this case inside _the_ constuctor:
>
> class MyClass:
> def __init__(arg):
> if type(arg) == type(0):
> self.a = arg
> elif isinstance(arg, MyObject):
> self.my = arg
>
> in the latter case, arg is a MyObject or a
> subclass of it (as with Java)
>
> HTH,
> Karl
Hi Karl
thanks a lot !!
Markus
More information about the Python-list
mailing list