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

> Hi Guys
> 
> 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. 
> 
> I have got 2 classes here 
> 
> 1. CEmployee
> 
> class CEmployee
>     def initialize()
>         puts "inside CEmployee"
>     end    
> end
> 
> 2. CManager
> 
> class CManager < CEmployee
>     def initialize()
>         puts "inside CManager"
>     end
> end
> 
> 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". 

> 
> 
>     objManager = CManager.new
> 
> 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.

>