• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




cannot find symbol
symbol : constructor Inherit()
location: class Inherit
public InheritB(int a,int b,int c) {


Why do I get this error?
thank you
 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This will work:



Why do I get this error?



you will have to define a call to super explicitly. Compiler is trying to use super(); in your case. But you super class does not have non parametrized constructor.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thank you
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add the following constructor to Inherit.java, :

//need a default constructor
public Inherit()
{}
//end of constructor
.....
try it.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you create object for InheritB(child class) a constructor for its parent class will be called implicitly. By default, the compiler looks for the zero argument constructor in the parent class. Now you have explicitly provided a constructor for Inherit class. If you hadn't, then compiler would have provided a zero argument constructor for you.
So there are 2 solutions for the program to work as described by the previous replies. One is, provide a zero argument constructor in Inherit class in addition to the already existing constructor. Second one, is by telling compiler not to look for the default zero argument constructor in parent class and call the one which you have created(using super). Since i and j will be initialized using super call, you don't have to explicitly initialize them in InheritB constructor.


Rahul
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you need parameters for your constructor in the superclass, then don't add a no-parameter constructor. Put the appropriate arguments in the super() call in the subclass constructor. If you search, you can find some old threads which are helpful: here are a few which might or might not help 1, 2, 3.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic