-1

when I have Super class Named Person

   public class Person {
         int Mobilenum;
           String Name;
             double GPA;                                           

public Person() {
    GPA = 2.23;
    Name = "Ramez";
    
}

and in the subclass when I make default constructor

if I want him to take same constructor like the Person class and what if I left the default constructor blank in the employee class

I have to make it like this?

public Employee() {
                super();
        }

or I don't have to write the Super keyword because it's a default constructor?

1 Answers1

0

All constructors must, by definition, start with a call to another constructor (this(someArgs);), or to a super constructor (super(someArgs);). If they don't, then the compiler will silently assume that you meant to start off with super();. Yes, it means any constructor whose parent class has no no-args constructor must start with super(something) or this(something) or it isn't going to compile.

If you have no constructors at all, javac will silently assume you meant to write a no-args public constructor.

These two rules combine. It means any class that has no constructors gets one for free, that takes no arguments, and whose content is super().

In other words, no need to write any constructor.

rzwitserloot
  • 65,603
  • 5
  • 38
  • 52