what is constructor chaining ?????
explain with example in detail how to solve it program plz send a program
-
Anirudha - 4111 Views
- 8 Answers
Constructor chaining is the process of calling one constructor from another constructor with respect to current object.br /// Java program to illustrate Constructor Chainingbr /// within same class Using this() keywordbr /class Tempbr /{br / // default constructor 1br / // default constructor will call another constructorbr / // using this keyword from same classbr / Temp()br / {br / // calls constructor 2br / this(5);br / System.out.println("The Default constructor");br / }br / br / // parameterized constructor 2br / Temp(int x)br / {br / // calls constructor 3br / this(5, 15);br / System.out.println(x);br / }br / br / // parameterized constructor 3br / Temp(int x, int y)br / {br / System.out.println(x * y);br / }br / br / public static void main(String args[])br / {br / // invokes default constructor firstbr / new Temp();br / }br /}br /Run on IDEbr /Output:br /The Default constructor 5 75
-
- 16 May
- 0 Comments
- Share
Didn't get the answer.
Contact people of Talent-Core Java directly by clicking here
-
How to iterate through a text file and search records in a java program?
-
What are the best way to get more knowledge about programming
-
Why does arguments in the methods are initialized with their default value in Java?
-
How do I stop getting emails from this website?
-
In This Program uses the topic are String and StringBuffer and etc.
-
can i compile a java file using classpath and that java file is present in some other directory
-
How does Yout4Work place students based on percentile?
-
this program is not working correctly
-
Illgal argument Exception in getDeclaredConstructor
-
1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5