tampurus

36 Constructor chaining

May 2nd, 2022 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.36 KB | None | 0 0
  1. class Temp
  2. {
  3.     Temp()
  4.     {
  5.         System.out.println("default");
  6.     }
  7.     Temp(int x)
  8.     {
  9.         this();
  10.         System.out.println(x);
  11.     }
  12.     Temp(int x, int y)
  13.     {
  14.         this(5);
  15.         System.out.println(x * y);
  16.     }
  17.  
  18.     public static void main(String args[])
  19.     {
  20.         new Temp(8, 10);
  21.     }
  22. }
  23. // output
  24. default
  25. 5
  26. 80
Add Comment
Please, Sign In to add comment