Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

JAVA n-arg Constructor

When the constructor taking parameters is known as n-arg or parameterized constructor.

Here in this context, instance variables equals local variables. Let’s see an example;

class A
  int x,y;
  A(int p,int q)    //parametrized constructor
  void show()
class ConstructorExample2
  public static void main(String[] args)
		A obj=new A(300,400);;



Here in this example x, y are instance variables and p, q are local variables. According to the concept x=p and y=q. We know that when an object is created, the constructor execute automatically. Here at the time of declaration of object obj we have passed value 300 and 400. So 300 will assign to p and 400 will assign to q then the p value will assign to x and q value will assign to y. Then finally x=300 and y=400 as output.

About the Author

Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc