inheritance from a library class (jar)

Can I extend a class which is in a jar file? Eclipse gives

Implicit super constructor Bord() is undefined. Must explicitly invoke another constructor

import mtg.Bord;

publicclass BordImplextends Bord{

public BordImpl(){...}

}

[534 byte] By [_topaz_] at [2007-9-30 23:29:04]
# 1
note that the parent class does contain a constructor...
_topaz_ at 2007-7-7 14:32:03 > top of Java-index,Security,Event Handling...
# 2

And my guess is the constructor requires one or more arguments. You need to create a constructor in the child class with a call to the super constructor with the correct arguments.

So if the super class constructor is public SuperClass(int v)

then the child class must have a constructorpublic ChildClass() { //may or may not have arguments

super(some_int_value); //first line in constructor

atmguy at 2007-7-7 14:32:03 > top of Java-index,Security,Event Handling...
# 3

Yes, you can, if the class isn't final, and has at least one protected or public constructor. (All classes have at least one constructor.)

There's apparently no default (no-arg) constructor, so like the message says, you have to explicitly invoke one. If there are no protected or public constructors, then you can't extend that class.

Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.

1) Every class has at least one ctor.

1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().

1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...}

if you want one.

1.3) Constructors are not inherited.

2) The first statement in the body of any ctor is either a call to a superclass ctor super(...)

or a call to another ctor of this class this(...)

2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super()

as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.

2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

jverd at 2007-7-7 14:32:03 > top of Java-index,Security,Event Handling...