Posts

Showing posts with the label default constructor in java

Java Constructors (Default + Parameterized)

Java Constructors: Default and Parameterized (With Examples) ✨ Quick Summary In this post, you’ll learn what Constructors are in Java and why they are used. We will cover default constructors , parameterized constructors , and how constructors help in initializing objects with simple examples. Java OOP Constructor OOP Concepts In our previous post, we learned about Java OOP and understood the basics of Class and Object . Now it’s time to learn an important OOP concept: Constructors . 1) What is a Constructor? A constructor is a special method used to initialize objects in Java. It is called automatically when an object is created. Example: Student s1 = new Student(); When this line runs, the constructor gets called automatically. 2) Constructor Rules in Java ✅ Constructor name must be same as the class name ✅ Constructor does not have a return type (not even void) ✅ Constructor is called aut...