1

This is my parent class

public abstract class Human {


   public Human(String name,String surname, int idno){

   }
}

And this is subclass

public class Personel extends Human {



    public Personel(String name,String surname, int idno)
    {

    }

}

personels constructor doesnot have to be same with parent class's but what ever i do, it gives error.

I will add final regnumber to personel, it cant be changed but i cant add this.

Why cant i make this:

public Personel()
    {todo

    }

or

public Personel();

or

public Personel(String name,String surname, int idno,int asda, string asdsa)
    {

    }

or

public Personel(final regnum)
    {

    }

If you help, i will be glad.

I did that, thanks but now i want to take inputs from user than make for example human1 object.

I have a main class, i want to create an object Human human1=new human();

What can i do now? It doesnot accept.

Human human1=new human(); i have to put in parantheses but i want to take from user, but i defined in constructor 3 parameters so, before class should i do that?

CursedChico
  • 571
  • 4
  • 7
  • 17
  • And what does the error message say? Don't you think it could contain interesting information? – JB Nizet Jul 16 '13 at 10:34
  • Sorry. It is that: Multiple markers at this line - Method breakpoint:Personel [entry] - Personel(String, String, int) - Implicit super constructor Human() is undefined. Must explicitly invoke another constructor – CursedChico Jul 16 '13 at 10:48
  • If you had pasted this error message in google, the first result would have told you the answer. – JB Nizet Jul 16 '13 at 10:49
  • You already have 5 answers explaining what to do. Why don't you read them? – JB Nizet Jul 16 '13 at 11:03

6 Answers6

2

You need to make your Personel constructor chain to the superclass constructor, e.g.

public Personel(String name, String surname, int idno) {
    super(name, surname, idno);
}

Here the super call is the constructor chaining. You don't have to use the same parameters as in your declared constructor - but you do need to chain to the superclass constructor either directly or via another constructor in the same class. For example, it's not clear what the superclass constructor parameters would be in your last case with regnum (which doesn't even have a type, for some reason...)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks. I did that and it seems ok: public Personel(String name,String surname, int idno,final int regnum) { super(name,surname,idno); } – CursedChico Jul 16 '13 at 10:50
1

Because you missed to invoke the super class constructor :

public Personel(String name,String surname, int idno)
{
   super(name,surname,idno);
}
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
1

You can make:

public Personel() {
     super("","",-1);
     ...
}
dijkstra
  • 1,068
  • 2
  • 16
  • 39
1

Please add the following constructor with explicit super call to invoke super class constructor having String, String, int parameters.

public Personel(String name, String surname, int idno) {
    super(name, surname, idno);
}
Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76
0

See JLS http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8.9

It is a compile-time error if a default constructor is implicitly declared but the superclass does not have an accessible constructor (§6.6) that takes no arguments and has no throws clause.

So Either you declare no argument constructor which has no throws clause in the abstract class.

 public abstract class Human {
    public Human(){
    }
  }

or call the abstract class constructor from you class

public Personel(String name, String surname, int idno) {
    super(name, surname, idno);
}
veritas
  • 2,444
  • 1
  • 21
  • 30
0

Per Oracle docs http://goo.gl/S8B3A "If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem. "

So u have to call :

  super(name, surname, idno);

in your

 public Personel(String name,String surname, int idno)
Kisanagaram
  • 289
  • 2
  • 10