**constructors are 'special'
They CANNOT be INHERITED If a class has no constructor defined, then compiler creates a default constructor(with no arguments) for the class. No-argument constructor: A constructor that has no parameter is known as default constructor.public class Crazy{ } public class CrazyClient{ public static void main(String[]args){ // no-argument constructor provided by compiler Crazy cs157 = new Crazy(); // toString method inherited from Object superclass System.out.printf("\n cs157 is %s\n\n", cs157); } }
overload
two or more methods in the same class with method headers differing only in number and type of parameters in formal parameter list **constructors are 'special' but CAN BE overloaded (though programmer does not get to choose name or return type!!!)public class WhatsitA{ private myA; public WhatsitA(int a){ myA = a; } public WhatsitA(int a, int b){ myA = a*b; } public double getADouble(int num){ return num*num*num; } public double getADouble(){ return 2.71828182; } }
override
method in a class with EXACT SAME METHOD header as method in super class **constructors are 'special' AND CANNOT be overridden or inherited. Superclass constructors, however, CAN BE CALLED (ie, invoked)public class SpecialB extends WhatsitA{ // 'looks' like an override but is not public SpecialB(int a){ super(a); } // 'override' of method in superclass public double getADouble(){ return -999; } }