Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract class constructor

 
Harshana Dias
Ranch Hand
Posts: 343
  • 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: 343
  • 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
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic