This question already has an answer here:
I have defined 2 constructors but when I am printing number of constructors, I get 1. Why?
public class JavaApplication3 {
public JavaApplication3() {
System.out.println("Constructor");
}
JavaApplication3(String s){
System.out.println("Parameterized constructor" + s);
}
public static void main(String[] args) {
JavaApplication3 obj = new JavaApplication3();
Class<?> c = obj.getClass();
Constructor<?> [] constructors = c.getConstructors();
System.out.println("No of constructors: " + constructors.length);
}
}
Aucun commentaire:
Enregistrer un commentaire