Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract class constructor

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Though we cant create a instance of a abstract class (call the constructor) but if we call the constructor of that abstract class via the sub class dont we instantiate the abstract class which is not possible?

eg:

abstract class Product {
int x;
public Product( int x ) {
this.x = x;
}
}

class Test extends Product {
public Test() {
super(2);
}
}


Thank You.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instance of a abstract class (call the constructor)

I would not put it that way. I would say "invoke new" instead. Calling a constructor doesn't instanciate anything. Invoking "new" does.

if we call the constructor of that abstract class via the sub class dont we instantiate the abstract class which is not possible?

No, you instanciate a concrete implementation of Product.
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh yes. forgot some simple java concepts because of out of touch..kind of refreshing them for a interview...thankx for remind me chris
 
sindhu somisetty
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey nice post ,I learnt new concept today ,thankuu friend
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic