Java Constructors Explanation
Java Constructors Explanation
What is a Constructor?
----------------------
A constructor is a special method in a class that is automatically called when you create an object of
the class.
Rules of Constructors:
- The constructor name must be the same as the class name.
- Constructors do not have a return type.
- They are used to initialize objects.
Types of Constructors:
----------------------
Car(String carModel) {
model = carModel;
System.out.println("Car model is: " + model);
}
Car(String model) {
System.out.println("Model: " + model);
}