The superclass:
public class Modem {
Modem(){
System.out.println("The Modem Constructor");
}
Modem(String entry){
System.out.println("The " +entry);
}
}
The subclass:
public class CableModem extends Modem {
CableModem(String entry){
System.out.println("The " + entry);
}
CableModem(){
System.out.println("The CableModem Constructor");
}
}
Main class:
public class Main {
public static void main(String[] args) {
CableModem cMod = new CableModem();
Modem mod = new Modem();
}
}
The output that i get:
The Modem Constructor
The CableModem Constructor
The Modem Constructor
So when I create an object of the subclas, both its and the supperclass constructors are being called. Why is this happening, and how can I prevent it from happening?