What is Constructor Chaining in Java | Constructor Chaining.
Code:
package com.impJavaConcepts;
class demo{
//super() - calls immediate parent class constructor
//super() - INHERITANCE is mandatory
//super() - first statement inside constructor
//super() and this() cannot be written in same constructor
demo(){
this(7);
System.out.println("this is a default constructor of demo class");
}
demo(int c){
System.out.println("This is integer constuctor of demo class");
}
}
public class ConstructorChaining {
//Calling a constructor from another constructor
//this() and super()
//this should always be first statement inside constructor
//Constructor Overloading
ConstructorChaining(){
this(5);
System.out.println("This is Default Construtor");
}
ConstructorChaining(int i){
this("Azhar Techno Coder");
System.out.println("This is int type Construtor");
}
ConstructorChaining(String s){
super();
System.out.println("String Constructor");
}
public static void main(String[] args) {
ConstructorChaining rv = new ConstructorChaining();
}
}
Chapters:
0:00 - Introduction to the video
0:31 - Achieving Constructor Chaining using this() Statement.
4:26 - Achieving Constructor Chaining using super() Statement.
6:25 - Achieving Constructor Chaining using super() Statement and this() statement.
7:08 - Super() only does constructor chaining if inheritance exists
7:36 - Rules of Super() statement.
Next Steps :
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
Must Watch Playlists
► 1. Javascript - • Javascript Factory
► 2. Puppetter - • Puppeteer
► 3. Cypress - • Cypress
► 4. Tech works - • Video
► 5. Vbscript Basics To Advanced - • VBScript Part 1 - Features Advantages Dis...
► 6. Jmeter - • Jmeter Tutorials
► 7. Excel - • Videos On Excel
► 8. Appium - • Appium
► 9. Shares - • Shares
► 10. Javascript Interview Questions - • Javascript Interview Questions
► 11. C# Tutorials - • C# Factory
► 12. HTML & CSS - • HTML & CSS
► 13. Browser Console - • Browser Console
► 14. JSON - • Videos on Json
► 15. Specflow - • Specflow Tutorials
► 16. MongoDB - • MongoDB Tutorials
► 17. Postman - • Postman
► 18. Python - • Python
► 19. Typescript - • Typescript & Node Imp Questions
► 20. Node - • Node
► 21. Java Selenium Interview Questions: • Java and Selenium Imp
► 22. Real Time Interview Q & A: • Real Time Interview Questions
► 23.SOAP UI Tutorials : • SOAP UI
► 24. WebDriverIO : • Getting Started with WebdriverIO | Install...
► 25. Jenkins : • How to download and install Jenkins on Win...
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
#java
#constructorChaining
#javatutorial