• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

is default constructor needed for the base class?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I met a quite hard question in bill's mock simulation:
Given the following class definition:
1.public class DeriveDemo extends Demo{
2. int M,N,L;
3. public DerivedDemo(int x, int y){
4. M=x; N=y;
5. }
6. public DerivedDemo(int x){
7. super(x);
8. }
9.}
it asks what contstructor signatures MUST exits in the Demo Class for DerivedDemo to complide correctly.
however, beside the once choice: public Demo(int c)
it also choose: public Demo()
saying that it is required because a default(no arguments) constructor is needed to compile the constructor starting in line 3.
I am quite confused about this explanation, can any one help me?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the constructor public DerivedDemo(int x, int y) is not explicitly calling the base class version like the other one public DerivedDemo(int x).Then it will call a default no args constructor of the super class. So we must provide a Demo() no args constructor in the Demo class.
This is not provided by the compiler because there is already a constructor Demo(int) in the super class.


Hi, I met a quite hard question in bill's mock simulation:
Given the following class definition:
1.public class DeriveDemo extends Demo{
2. int M,N,L;
3. public DerivedDemo(int x, int y){
4. M=x; N=y;
5. }
6. public DerivedDemo(int x){
7. super(x);
8. }
9.}

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic