File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance" Watch "inheritance" New topic


kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87

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
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 415

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.

Pawan Chopra
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87

thank you
birun takhellambam

Joined: Mar 06, 2010
Posts: 4
add the following constructor to, :

//need a default constructor
public Inherit()
//end of constructor
try it.

Rahul Kurup

Joined: Dec 11, 2009
Posts: 9
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 J.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46424
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.
It is sorta covered in the JavaRanch Style Guide.
subject: inheritance
It's not a secret anymore!