
🚀 Day 7 of My Automation Journey – Default Values & Constructors in Java
Today I learned two very important concepts in Java: ✅ Default Values ✅ Constructors ✅ Object Initialization This is where Java becomes more practical and object-oriented. 🔹 What Are Default Values in Java? When we declare instance variables (class-level variables) and do not assign values, Java automatically assigns default values. 📌 Default Values of Data Types Data Type Default Value int 0 double 0.0 float 0.0f boolean false char '\u0000' (empty character) String null 👉 Important: Default values are assigned only to instance variables, not local variables. 🔹 What Is a Constructor? A constructor: Has the same name as the class Is automatically called when object is created Has no return type Is used to initialize object-specific values Syntax public ClassName(parameters) { // initialization } 🔹 Real Example – SuperMarket Program Let’s understand the code step by step. package java_Module_2_Constructor; public class SuperMarket { String prod_name, Quantity; int price, discount; public
Continue reading on Dev.to
Opens in a new tab

