Java Class getDeclaredConstructor() MethodThe getDeclaredConstructoe() method of java Class class returns a constructor object representing all the constructors present in the class. SyntaxParameterparameterTypes - the parameter array ReturnsConstructor object. ThrowsNoSuchMethodException , SecurityException Example 1Test it NowOutput: Constructor with no parameter : public ClassgetDeclaredConstructorExample1() Constructor with int as parameter type : public ClassgetDeclaredConstructorExample1(int) Constructor with String as parameter type : private ClassgetDeclaredConstructorExample1(java.lang.String) Example 2Test it NowOutput: Default constructor Constructor = public ClassgetDeclaredConstructorExample2(java.lang.Double,java.lang.Long)
Next TopicJava Class
|