How to create constructors for a class?
Every class in Java has a constructor. constructor is a method that is use to create an instance or object of the class. Every time you create an instance, you must invoked a constructor.
If you do not create a constructor method of your class, the compiler will build a default one. A default constructors is a constructor that accept no argument.
Things to be noted when you declare a constructor:
- constructor must have the same name as the class in which they are declared
- constructor can't have a return type
- constructor can have access modifier
- constructor can take arguments
- constructor can't be marked static
- constructor can't be marked final or abstract