• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

constructor question

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic