Can we call an constructor from an another constructor?
Yes, we can.
We can use this() statement to call another constructor that belongs to the same class.
This process of calling an constructor from an another is called constructor chaining.
e.g,
public class Example{
public Example(){
System.out.println("Con");
}
public Example(String name){
System.out.println(name);
this(); // call the zero parameter constructor.
}
public static void main(String[] args){
Example ex = new Example("Vasu");
}
}
Note: Make sure you call an different constructor to avoid recursion.
Packages in java:
Packages -> It is a grouping technique used to group the source files.
It also grant access control to our classes.
We can easily maintain our code, maintainablity is one of the main idea behind the packages.
Package name must be in small case.
We cannot use the another package classes into our program until we explicitly import them.
syntax: package accounts;