On Nov 6, 2011, at 7:16 PM, Ankush Ganatra wrote:

> Hi Guys
>=20
> I am a little confused and need some help. I am a newbie for Ruby but =
i think i understand Object Oriented programming a little bit so i got =
confused here.=20
>=20
> I have got 2 classes here=20
>=20
> 1. CEmployee
>=20
> class CEmployee
>     def initialize()
>         puts "inside CEmployee"
>     end   =20
> end
>=20
> 2. CManager
>=20
> class CManager < CEmployee
>     def initialize()
>         puts "inside CManager"
>     end
> end
>=20
> Now if i create an Object of CManager class (unlike other languages =
like C++ ) the constructor of it gets called but not the base class =
"Until i use the super keyword".=20

>=20
>=20
>     objManager =3D CManager.new
>=20
> Can someone please help me here? And even if the this is supposed to =
be working like this, isn't it something different from the Object =
Oriented Concept which says base class constructor always gets called =
first?


This is how it is supposed to work indeed, in Ruby there's no notion of =
default constructor like in C++ (a non-default constructor must be =
invoked explicitly even there). With a call to super, a subclass can =
choose how a superclass constructor is invoked in regards to passed =
parameters and the order of statements. Or not to invoke it at all.

And this is not something unheard of in Object Oriented Concept world. =
Just look at Objective-C for quick examples, where a subclass is =
responsible also for its superclass allocation, not only initialization.

Genandy.

>=20