In earlier article, we had declared a class, added member method, member method. We created instance of our object.
In this article, we will be looking what is constructor in java class.
Lets look to syntax of constructor in a java class.
public class servers
{
String ostype;
String ip;
String hostname;
public servers()
{
ostype = "not provided";
ip = "unknown";
hostname = "unknown";
}
}
Lets see it in Java class example.
In above example, in our class "server" which contains member field: "ostype", "ip", and "hostname". In our java example, we added a constructor to class. when an object is created of that class, by default "unknown" value is assigned to member field values of objects.