Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

java programmer certificate

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic