{"id":3954,"date":"2024-09-10T12:31:47","date_gmt":"2024-09-10T07:31:47","guid":{"rendered":"https:\/\/afzalbadshah.com\/?p=3954"},"modified":"2025-07-03T09:05:35","modified_gmt":"2025-07-03T04:05:35","slug":"constructors-in-oop","status":"publish","type":"post","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/","title":{"rendered":"Constructors in Java: Types and Overloading Explained with Real-Life Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key Features:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A constructor has the same name as the class.<\/li>\n\n\n\n<li>It has no return type, not even void.<\/li>\n\n\n\n<li>It is automatically invoked when an object is created.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-Life Analogy: Preparing a Car Before Driving<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine you&#8217;re buying a new car. When you go to the dealership, you have a few choices:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can give all your preferences like color, make, and model. The dealer prepares the car exactly as you asked.<\/li>\n\n\n\n<li>You might just say, &#8220;I want a red car,&#8221; and the dealer chooses the rest.<\/li>\n\n\n\n<li>Or, you don&#8217;t give any preferences, and the dealer gives you a default version with basic features.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, this is exactly what constructors do:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>They set up your object when it&#8217;s created.<\/li>\n\n\n\n<li>They can be given full information (custom setup), partial information (partial setup), or no information (default setup).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Types of Constructors in Java<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java provides two types of constructors:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Default Constructor (No-Argument Constructor)<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Takes no parameters.<\/li>\n\n\n\n<li>Sets fields to default or fixed values.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Think of this as a car dealership giving you a basic car model without asking for any input. You didn\u2019t select color, make, or model \u2014 so they give you the default package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Car {\n    private String color;\n    private String make;\n    private String model;\n\n    \/\/ Default constructor\n    public Car() {\n        this.color = \"Unknown\";\n        this.make = \"Unknown\";\n        this.model = \"Unknown\";\n    }\n\n    public void showDetails() {\n        System.out.println(\"Color: \" + color);\n        System.out.println(\"Make: \" + make);\n        System.out.println(\"Model: \" + model);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Usage:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n    public static void main(String&#91;] args) {\n        Car defaultCar = new Car();\n        defaultCar.showDetails();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Color: Unknown\nMake: Unknown\nModel: Unknown\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Parameterized Constructor<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Takes arguments to initialize object fields with custom values.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This is like going to the car dealership and specifying exactly what you want: &#8220;I want a Red Toyota Corolla.&#8221; The constructor uses your input to prepare the car accordingly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Car {\n    private String color;\n    private String make;\n    private String model;\n\n    \/\/ Parameterized constructor\n    public Car(String color, String make, String model) {\n        this.color = color;\n        this.make = make;\n        this.model = model;\n    }\n\n    public void showDetails() {\n        System.out.println(\"Color: \" + color);\n        System.out.println(\"Make: \" + make);\n        System.out.println(\"Model: \" + model);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Usage:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n    public static void main(String&#91;] args) {\n        Car myCar = new Car(\"Red\", \"Toyota\", \"Corolla\");\n        myCar.showDetails();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Color: Red\nMake: Toyota\nModel: Corolla\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Constructor Overloading<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Constructor Overloading is a feature that allows us to define multiple constructors in the same class, as long as each has a different parameter list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-Life Analogy:<\/strong><br>Just like at a dealership, a customer may:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Provide no details and take the default model<\/li>\n\n\n\n<li>Specify only the color and let the dealer choose the rest<\/li>\n\n\n\n<li>Provide all details to get exactly what they want<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Constructor overloading allows the class to respond to all these situations by providing several ways to set up an object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Car Class with Constructor Overloading<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Car {\n    private String color;\n    private String make;\n    private String model;\n\n    \/\/ Default constructor\n    public Car() {\n        this.color = \"Unknown\";\n        this.make = \"Unknown\";\n        this.model = \"Unknown\";\n    }\n\n    \/\/ Constructor with one parameter\n    public Car(String color) {\n        this.color = color;\n        this.make = \"Unknown\";\n        this.model = \"Unknown\";\n    }\n\n    \/\/ Constructor with three parameters\n    public Car(String color, String make, String model) {\n        this.color = color;\n        this.make = make;\n        this.model = model;\n    }\n\n    public void showDetails() {\n        System.out.println(\"Color: \" + color);\n        System.out.println(\"Make: \" + make);\n        System.out.println(\"Model: \" + model);\n        System.out.println(\"----------------------\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Usage Example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n    public static void main(String&#91;] args) {\n        Car car1 = new Car(); \/\/ No details provided\n        Car car2 = new Car(\"Blue\"); \/\/ Only color provided\n        Car car3 = new Car(\"Black\", \"Honda\", \"Civic\"); \/\/ All details provided\n\n        car1.showDetails();\n        car2.showDetails();\n        car3.showDetails();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Color: Unknown\nMake: Unknown\nModel: Unknown\n----------------------\nColor: Blue\nMake: Unknown\nModel: Unknown\n----------------------\nColor: Black\nMake: Honda\nModel: Civic\n----------------------\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Summary<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Constructors are used to initialize objects at creation time.<\/li>\n\n\n\n<li>Java has two types of constructors: Default and Parameterized.<\/li>\n\n\n\n<li>Constructor overloading allows multiple constructors with different signatures, offering flexibility for object creation.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-canva wp-block-embed-canva\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Constructors in OOP\" src=\"https:\/\/www.canva.com\/design\/DAGQVpSUiX4\/ijGWd3OLxyzEZ-6_rEJaUQ\/view?embed&amp;meta\" height=\"360\" width=\"640\" style=\"border: none; border-radius: 8px; width: 640px; height: 360px;\" allowfullscreen=\"allowfullscreen\" allow=\"fullscreen\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: Real-Life Analogy: Preparing a Car Before Driving Imagine you&#8217;re buying a new car. When you go to the dealership, you have a few choices: In Java, this is exactly what constructors do: Types of Constructors in Java Java provides two types of constructors: 1. Default Constructor (No-Argument Constructor) Think of this&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3955,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[602],"tags":[614,604,603],"class_list":["post-3954","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-object-oriented-programing-oop","tag-constructor","tag-object-oriented-programing","tag-oop"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Afzal Badshah, PhD\"\/>\n\t<meta name=\"google-site-verification\" content=\"B8FNGv4w1toMpU3HUnD_SN9H9YMtp1ObsLuEDuirArI\" \/>\n\t<meta name=\"p:domain_verify\" content=\"87b5ca26c36438b20581a102dc290a47\" \/>\n\t<meta name=\"yandex-verification\" content=\"0eb3e2a9157fd34d\" \/>\n\t<meta name=\"keywords\" content=\"constructor,object oriented programing,oop,object oriented programing (oop)\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_GB\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Afzal Badshah, PhD - Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD\" \/>\n\t\t<meta property=\"og:description\" content=\"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2024-09-10T07:31:47+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2025-07-03T04:05:35+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/web.facebook.com\/abmanduri\/\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@DrAFZALBADSHAH\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@DrAFZALBADSHAH\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp\" \/>\n\t\t<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t\t<meta name=\"twitter:data1\" content=\"Afzal Badshah, PhD\" \/>\n\t\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#blogposting\",\"name\":\"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD\",\"headline\":\"Constructors in Java: Types and Overloading Explained with Real-Life Examples\",\"author\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/afzalbadshah.com\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Constructors-in-OOP-jpg.webp?fit=1920%2C1080&ssl=1\",\"width\":1920,\"height\":1080},\"datePublished\":\"2024-09-10T12:31:47+05:00\",\"dateModified\":\"2025-07-03T09:05:35+05:00\",\"inLanguage\":\"en-GB\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#webpage\"},\"articleSection\":\"Object Oriented Programing (OOP), constructor, object oriented programing, OOP\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/afzalbadshah.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"name\":\"Courses\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"position\":2,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/object-oriented-programing-oop\\\/#listItem\",\"name\":\"Object Oriented Programing (OOP)\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/object-oriented-programing-oop\\\/#listItem\",\"position\":3,\"name\":\"Object Oriented Programing (OOP)\",\"item\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/object-oriented-programing-oop\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#listItem\",\"name\":\"Constructors in Java: Types and Overloading Explained with Real-Life Examples\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"name\":\"Courses\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#listItem\",\"position\":4,\"name\":\"Constructors in Java: Types and Overloading Explained with Real-Life Examples\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/object-oriented-programing-oop\\\/#listItem\",\"name\":\"Object Oriented Programing (OOP)\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\",\"name\":\"Afzal Badshah, PhD\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#personImage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/wp-content\\\/litespeed\\\/avatar\\\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587\",\"width\":96,\"height\":96,\"caption\":\"Afzal Badshah, PhD\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/\",\"name\":\"Afzal Badshah, PhD\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#authorImage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/wp-content\\\/litespeed\\\/avatar\\\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587\",\"width\":96,\"height\":96,\"caption\":\"Afzal Badshah, PhD\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#webpage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/\",\"name\":\"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD\",\"description\":\"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.\",\"inLanguage\":\"en-GB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/afzalbadshah.com\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Constructors-in-OOP-jpg.webp?fit=1920%2C1080&ssl=1\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#mainImage\",\"width\":1920,\"height\":1080},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/09\\\/10\\\/constructors-in-oop\\\/#mainImage\"},\"datePublished\":\"2024-09-10T12:31:47+05:00\",\"dateModified\":\"2025-07-03T09:05:35+05:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#website\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/\",\"name\":\"Afzal Badshah, PhD\",\"alternateName\":\"Afzal Badshah\",\"description\":\"Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence\",\"inLanguage\":\"en-GB\",\"publisher\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD","description":"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.","canonical_url":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/","robots":"max-image-preview:large","keywords":"constructor,object oriented programing,oop,object oriented programing (oop)","webmasterTools":{"google-site-verification":"B8FNGv4w1toMpU3HUnD_SN9H9YMtp1ObsLuEDuirArI","p:domain_verify":"87b5ca26c36438b20581a102dc290a47","yandex-verification":"0eb3e2a9157fd34d","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#blogposting","name":"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD","headline":"Constructors in Java: Types and Overloading Explained with Real-Life Examples","author":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"publisher":{"@id":"https:\/\/afzalbadshah.com\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp?fit=1920%2C1080&ssl=1","width":1920,"height":1080},"datePublished":"2024-09-10T12:31:47+05:00","dateModified":"2025-07-03T09:05:35+05:00","inLanguage":"en-GB","mainEntityOfPage":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#webpage"},"isPartOf":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#webpage"},"articleSection":"Object Oriented Programing (OOP), constructor, object oriented programing, OOP"},{"@type":"BreadcrumbList","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com#listItem","position":1,"name":"Home","item":"https:\/\/afzalbadshah.com","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","name":"Courses"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","position":2,"name":"Courses","item":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/object-oriented-programing-oop\/#listItem","name":"Object Oriented Programing (OOP)"},"previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/object-oriented-programing-oop\/#listItem","position":3,"name":"Object Oriented Programing (OOP)","item":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/object-oriented-programing-oop\/","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#listItem","name":"Constructors in Java: Types and Overloading Explained with Real-Life Examples"},"previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","name":"Courses"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#listItem","position":4,"name":"Constructors in Java: Types and Overloading Explained with Real-Life Examples","previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/object-oriented-programing-oop\/#listItem","name":"Object Oriented Programing (OOP)"}}]},{"@type":"Person","@id":"https:\/\/afzalbadshah.com\/#person","name":"Afzal Badshah, PhD","image":{"@type":"ImageObject","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#personImage","url":"https:\/\/afzalbadshah.com\/wp-content\/litespeed\/avatar\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587","width":96,"height":96,"caption":"Afzal Badshah, PhD"}},{"@type":"Person","@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author","url":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/","name":"Afzal Badshah, PhD","image":{"@type":"ImageObject","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#authorImage","url":"https:\/\/afzalbadshah.com\/wp-content\/litespeed\/avatar\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587","width":96,"height":96,"caption":"Afzal Badshah, PhD"}},{"@type":"WebPage","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#webpage","url":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/","name":"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD","description":"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.","inLanguage":"en-GB","isPartOf":{"@id":"https:\/\/afzalbadshah.com\/#website"},"breadcrumb":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#breadcrumblist"},"author":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"creator":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp?fit=1920%2C1080&ssl=1","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#mainImage","width":1920,"height":1080},"primaryImageOfPage":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/#mainImage"},"datePublished":"2024-09-10T12:31:47+05:00","dateModified":"2025-07-03T09:05:35+05:00"},{"@type":"WebSite","@id":"https:\/\/afzalbadshah.com\/#website","url":"https:\/\/afzalbadshah.com\/","name":"Afzal Badshah, PhD","alternateName":"Afzal Badshah","description":"Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence","inLanguage":"en-GB","publisher":{"@id":"https:\/\/afzalbadshah.com\/#person"}}]},"og:locale":"en_GB","og:site_name":"Afzal Badshah, PhD - Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence","og:type":"article","og:title":"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD","og:description":"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.","og:url":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/","og:image":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp","og:image:secure_url":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp","og:image:width":1920,"og:image:height":1080,"article:published_time":"2024-09-10T07:31:47+00:00","article:modified_time":"2025-07-03T04:05:35+00:00","article:publisher":"https:\/\/web.facebook.com\/abmanduri\/","twitter:card":"summary_large_image","twitter:site":"@DrAFZALBADSHAH","twitter:title":"Constructors in Java: Types and Overloading Explained with Real-Life Examples - Afzal Badshah, PhD","twitter:description":"In Java, a constructor is a special type of method used to initialize objects. It is called automatically when you create an object using the new keyword. Key Features: A constructor has the same name as the class. It has no return type, not even void. It is automatically invoked when an object is created.","twitter:creator":"@DrAFZALBADSHAH","twitter:image":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp","twitter:label1":"Written by","twitter:data1":"Afzal Badshah, PhD","twitter:label2":"Est. reading time","twitter:data2":"3 minutes"},"aioseo_meta_data":{"post_id":"3954","title":null,"description":null,"keywords":null,"keyphrases":{"focus":{"keyphrase":"Constructors in OOP","score":46,"analysis":{"keyphraseInTitle":{"score":3,"maxScore":9,"error":1},"keyphraseInDescription":{"score":3,"maxScore":9,"error":1},"keyphraseLength":{"score":9,"maxScore":9,"error":0,"length":3},"keyphraseInURL":{"score":5,"maxScore":5,"error":0},"keyphraseInIntroduction":{"score":3,"maxScore":9,"error":1},"keyphraseInSubHeadings":[],"keyphraseInImageAlt":[],"keywordDensity":{"score":0,"type":"low","maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":true,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"titles":[],"descriptions":[],"socialPosts":{"email":[],"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2024-09-10 07:31:50","updated":"2025-07-03 04:13:57","focus_keyword":"Constructors in OOP","additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/\" title=\"Courses\">Courses<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/object-oriented-programing-oop\/\" title=\"Object Oriented Programing (OOP)\">Object Oriented Programing (OOP)<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tConstructors in Java: Types and Overloading Explained with Real-Life Examples\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/afzalbadshah.com"},{"label":"Courses","link":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/"},{"label":"Object Oriented Programing (OOP)","link":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/object-oriented-programing-oop\/"},{"label":"Constructors in Java: Types and Overloading Explained with Real-Life Examples","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/09\/10\/constructors-in-oop\/"}],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/09\/Constructors-in-OOP-jpg.webp?fit=1920%2C1080&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pf3emP-11M","jetpack-related-posts":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/comments?post=3954"}],"version-history":[{"count":3,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3954\/revisions"}],"predecessor-version":[{"id":6374,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3954\/revisions\/6374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media\/3955"}],"wp:attachment":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media?parent=3954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/categories?post=3954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/tags?post=3954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}