aspose file tools*
The moose likes Beginning Java and the fly likes confuse statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "confuse statement" Watch "confuse statement" New topic
Author

confuse statement

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Jan 06, 2005
Posts: 140
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,


Lionel Badiou
CodeFutures Software
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks Lionel Badiou ,
Ultimate explanation .
Building a class mean constructing an object of class ... right ..
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
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

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Jan 06, 2005
Posts: 140
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,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confuse statement