wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes constructor question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructor question" Watch "constructor question" New topic
Author

constructor question

Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Hi

I came to know that in a inherited structure like a inherits b, b inherits c etc with each having a constructor when i create a object first constructor of Object is executed . Does it mean that memory for any object is actually defined in the Object(Object is the base class for all existing java objects) constuctor method ?
Also please help me with
what will happen if I create an A object and A doesn't have a constructor
defined whereas B has a constructor defined ?
What if in the above case B has a constructor with 2 arguments and I have to call it in A's constructor ?

Thanks
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Why you don't try write such class where A has default constructor and B has constructor with parameters? You will see what is the result.

But there will be compilation error.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

It means that every new type has some 'Object-ness' to it, yes. In recent versions of Java many elements of the Object class are made static to account for that fact.

Every new type has a constructor, no matter what. You can write the access rights to a constructor so that no one outside the class can call it, but there still must be a constructor for every class. It makes no difference if a class provides its own or if the compiler silently inserts one to maintain the chaining process back to java.lang.Object, the basae supertype.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructor question
 
Similar Threads
anonymous inner class and Constructor
Order Of Constructor calling
when costructor is call
quick class question
Marcus mock 3 No.43