• Post Reply Bookmark Topic Watch Topic
  • New Topic

The definition of instantiation for Abstract Superclass  RSS feed

 
Perry Terrance
Ranch Hand
Posts: 66
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I'm some bit-picky stuff right now, but I want to get my terminology straight here.

Everyone knows that Abstract classes cannot be instantiated "directly." However you can call its constructor via a subclass of that Abstract class thru "Super()".

Is doing this considered "instantiation" that Abstract class since you are calling its constructor?

Cause isn't the whole definition of "instantiation" done by calling a constructor?

What happens then if I remove the Abstract notation from that superclass and instantiate the sub-class again. Wouldn't the JVM now definitely have at least two objects in memory, the subclass and the superclass?
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perry Terrance wrote:
Is doing this considered "instantiation" that Abstract class since you are calling its constructor?

Cause isn't the whole definition of "instantiation" done by calling a constructor?


Calling Super Class Constructor from Child Class is for --- Initialization of variables which are inherited by Child class from Super Class.

Instantiation means creating space for an object and also doing initialization.

Perry Terrance wrote:
What happens then if I remove the Abstract notation from that superclass and instantiate the sub-class again. Wouldn't the JVM now definitely have at least two objects in memory, the subclass and the superclass?

NO...refer above explanation...
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have one object which is created from the subclass . . . but part of it is created from the superclass too. Find a copy of Head First Java (Sierra and Bates) and find the diagrams with concentric circles showing objects being made up of different parts from different classes.
Anybody know which page that would be?
 
Perry Terrance
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I got it. In instantiating the subclass (with superclass being abstract or concrete), in the end the JVM has one and ONLY one object total (but with the data-structure from its superclasses as well). In the end - instantiation only occurs ONCE.

However this brings up a point. Calling a class constructor does NOT mean instantiation - correct? It only does initialization...

This gets confusing cause most Java tutorials always associates Constructors with Instantiation...

Am I getting this right?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perry Terrance wrote:This gets confusing cause most Java tutorials always associates Constructors with Instantiation...


Do they?

It's been a long time since I read those tutorials, so I went and looked at the Oracle tutorial about constructors. It just gives the basic information about constructors, namely that they instantiate an object and initialize it. However it doesn't go into the details of how that initialization takes place, it just says that using superclass constructors "will be discussed later, in the lesson on interfaces and inheritance".

Here's what another (not as good) tutorial has to say: "A constructor is a special method that is used to initialize a newly created object and is called just after the memory is allocated for the object."

The next tutorial I looked at didn't even bother to say what a constructor was supposed to do, it just plunged straight into describing how to write them. Nothing about either instantiation or initialization.

And the next one I looked at said "An object can be initialized (or as it's said instantiated) with the keyword new" -- so it didn't even distinguish between the two concepts!

Anyway after reviewing those tutorials I would suggest that the Oracle tutorial is the one you should read, rather than all the other ones. But if your question is about abstract classes, then what you need to know is this: the rule is "If X is an abstract class then it isn't possible to create an object whose type is X". There's nothing about constructors in that rule, so if you have a question about constructors in the context of abstract classes, then you are misinterpreting the rule. Which is a very simple rule.
 
Amruta Mistry
Greenhorn
Posts: 9
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You have one object which is created from the subclass . . . but part of it is created from the superclass too. Find a copy of Head First Java (Sierra and Bates) and find the diagrams with concentric circles showing objects being made up of different parts from different classes.
Anybody know which page that would be?
page: 236 chapter :9
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amruta Mistry wrote:. . . page: 236 chapter :9
Welcome to the Ranch and thank you. I was actually thinking of the drawings on pages 250-251 (the Snowboard diagram is copied from pages 214-215). Page 236 has different circles on.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!