What Happen if Parent Class or Superclass has a parameterized Constructor and child class Subclass extends or inherits Parent Class or Superclass in  Java?

Constructor Interview Question
Constructor Interview Question

public class Bank {

  Bank(int Loanrate) {

  }
 }
}

 class YesBank extends Bank {

 }
It gives you a Compile Time error saying: constructor Bank in class Bank cannot be applied to given types;

When a class doesn't have any constructor (as your YesBank class doesn't), the compiler generates a default constructor with no parameters.

This constructor invokes the non-parameterize(default constructor) constructor of the Superclass(Bank) and Superclass doesn't have any non-parameterize constructor that's why your code won't compile.

Note: Every Constructor has a super keyword in it.
 public class Bank {
     Bank(int Loanrate) {

     }
   }

 class YesBank extends Bank {
     /*YesBank(){
 super(); //this is Generate By compiler
        }*/
     YesBank(int a) {
         super(a);//this is Generate By User
     }
   }
This is the Simple Interview Question  of Constructor by Interviewer
أحدث أقدم