This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java programmer certificate

 
Kameshwar Prasad
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the fallowing code is from Jargon test (http://www.sarga.com)when this progra is being compiled giving

No constructor matching Base() found in class Base.
Child(int i) { test (); }
as there is no call for default base constructor in child class
why this error ?
<pre>

class Base
{
Base(int i) { test(); }
// Base(){}
void test() {
System.out.println("Base.test()");
}

}

public class Child extends Base {


byte b = 1 ;
Child(int i) { test (); }
Child(float f) { this ((int)f); }
void test() {
System.out.println("Child.test()");
}

static public void main(String[] a) {
new Child(10.8f).test();
}
}

</pre>

[This message has been edited by maha anna (edited April 23, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator

All base class constructors call the super class
constructor first. It is always considered a good
programming habit if you explicitly call (IMO).
If you donot explicitly call the super class
constructor explicitly, then the JDK will make the
call on your behalf. Since in this example you din't
make the call explicitly, JDK calls the default super
class constructor which takes no arguments. Now, in the
super class you did provide a constructor explicitly.
Hence the default constructor is not avail for this super
class. Hence the ERROR.
Hope this helps.
Regds.
- satya
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic