• Post Reply Bookmark Topic Watch Topic
  • New Topic

How a base object is creating while creating a child object, if base class is abstract ?  RSS feed

 
Indrajit Roy
Greenhorn
Posts: 4
IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the output is :


here while creating object of Child, object of Base is created automatically.
if an abstract class can't be instantiated, how the object of base is created?
while creating the Base object, how the abstract method is being implemented?
can anyone please explain?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indrajit Roy wrote:here while creating object of Child, object of Base is created automatically.

No, it isn't. There is no such thing as base object, or child object.

An instance of the child class is created with members inherited from the parent class. There is only one object created.
 
Indrajit Roy
Greenhorn
Posts: 4
IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but the constructor of the base class is invoked. what does this constructor do?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think the constructors are triggered on different objects?
 
Indrajit Roy
Greenhorn
Posts: 4
IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am just asking if the constructor of base class is invoked, what does it do?? just making a output line ??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All constructors in the class hierarchy are invoked on the newly-created object. Each is not called on separate objects.
 
Indrajit Roy
Greenhorn
Posts: 4
IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how the new object is created? who is creating it?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Language Specification tells you the order in which constructors are called; try §12.4 in that link.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!