Hi All,
I Have two class A and B.
I am reading a int number N where n belongs to natural number so n can be 1, 2, 3, 4, ......N and so on
Now in class A, i want to call the construtor of class B that takes N parameters.
class B
{
public B()
{
S.O.P("B"); /// SOP is for system.out.println
}
public B(String 1st)
{
S.O.P ("construtor with 1 parameter"); /// SOP is for system.out.println
}
public B(String 1st, String 2nd)
{
S.O.P("construtor with 2 parameters"); /// SOP is for system.out.println
}
}
in class B i can define construtor for 10 parameters or for 20 parameters but what if number of parameters can be more and if I am getting this number of parameters at runtime, then how can i define a construtor in class B with that number of parameters
I am reading an int input N in class A and want to call a construtor of class B that takes N parameters.
where n belongs to natural number so n = 1 2 3 4 .......infinitive.
class A
{
public static void main(String arg[])
{
System.out.println("Number of arguments for class B construtor " + arg[0]);
/// below step is problem what code i should use here to get a construtor of B that takes N parameters
// B b = new B(String str1, String str2, String str3 .......and so on this number of arguments must be equal to N or arg[0] value)
}
is there any way to define the constructor of any Class at runtime with the desired number of parameters?
i cant define construtor of class B manually for all values of n.
you can reply on
mailofpravin@gmail.com too