wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes abstract class constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract class constructor" Watch "abstract class constructor" New topic
Author

abstract class constructor

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
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

Joined: Nov 17, 2009
Posts: 2
hey nice post ,I learnt new concept today ,thankuu friend
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract class constructor