fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Complex
  5. {
  6. private:
  7. int a;
  8. int b;
  9. public:
  10. Complex()
  11. {
  12. cout<<"I am in constructor...";
  13. a=10;
  14. b=20;
  15. }
  16. Complex(int x,int y)
  17. {
  18. cout<<"Object created"<<endl;
  19. a=x;
  20. b=y;
  21. cout<<"a="<<a<<"\nb="<<b<<endl;
  22. }
  23. Complex(int x)
  24. {
  25. cout<<"Object created"<<endl;
  26. a=x;
  27. b=15;
  28. cout<<"a="<<a<<"\nb="<<b<<endl;
  29. }
  30. };
  31.  
  32. int main()
  33. {
  34. Complex c1(12,14);
  35. Complex c2(9);
  36. Complex c3;
  37. return 0;
  38. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
Object created
a=12
b=14
Object created
a=9
b=15
I am in constructor...