Java ClassesLesson 29Free preview
Java Constructors
This lesson is part of Java · All levels
Summary
A constructor is a special method that is automatically called when an object is created with new. The name should be exactly the same as the class name and have no return type. If you don't write constructors at all, Java will provide default constructors without parameters.
Key points
- The constructor has the same name as the class and without the return type
- The constructor runs automatically when the object is made using new
- More than one constructor with different parameters is called a constructor overloading
- When there's no constructor, Java creates the default constructor automatically.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.