Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confuse statement

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can't use instance members ( variable & methods ) untill the super class constructor has runs .

Why so ... I mean whats the logic behind it ... any exception in this ...

can any body help me to understand this better ...

thanks a lot ...
[ January 13, 2005: Message edited by: rathi ji ]
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rathi,

Can you imagine using a class without building its superclass first ?
You have to build fundations before building a house. A superclass is like fundations. A superclass is so always created *before* its subclasses.

A subclass simply doesn't yet exist before superclass creation (contructor's call), so you can't really think of using its members.

Best regards,
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lionel Badiou ,
Ultimate explanation .
Building a class mean constructing an object of class ... right ..
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Again,

Creating an instance of a class means creating an object of that class. This means :

- Allowing needed memory
- Performing initalisations

In other words, the constructor call of a given class ensure that a new instance (or object) is ready to use.

For a given class, the compiler creates first an instance of its superclass then creates the instance of the class itself.

I hope this is clearer ;-)
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lionel Badiou:
For a given class, the compiler creates first an instance of its superclass then creates the instance of the class itself.



Are you sure in this ....

What will happen when a class will extends abstract class ....
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

An abstract class is a class you declare abstract (can't be programmatically instancied). It's a convenient way to declare fundamental concepts of your OO design.
Similarly, a constant is basically a variable that you can't programmaticaly change. But the compiler manage both as memory location.

If an abstract class contains variables/methods, the compiler allocates memory and do initalisation as normal instance creation, when you create an instance of its subclass.

Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic