Java | Constructors | Question 6
final class Complex { private double re, im; public Complex(double re, double im) { this.re = re; this.im = im; } Complex(Complex c) { System.out.println("Copy constructor called"); re = c.re; im = c.im; } public String toString() { return "(" + re + " + " + im + "i)"; } } class Main { public static void main(String[] args) { Complex c1 = new Complex(10, 15); Complex c2 = new Complex(c1); Complex c3 = c1; System.out.println(c2); } } |
chevron_right
filter_none
(A)
Copy constructor called (10.0 + 15.0i)
(B)
Copy constructor called (0.0 + 0.0i)
(C)
(10.0 + 15.0i)
(D)
(0.0 + 0.0i)
Answer: (A)
Explanation:
Quiz of this Question
Recommended Posts:
- Java | Constructors | Question 2
- Java | Constructors | Question 8
- Java | Constructors | Question 5
- Java | Constructors | Question 3
- Java | Constructors | Question 1
- Java | Constructors | Question 4
- Why Constructors are not inherited in Java?
- Order of execution of Initialization blocks and Constructors in Java
- C++ | Constructors | Question 10
- C++ | Constructors | Question 17
- C++ | Constructors | Question 12
- C++ | Constructors | Question 16
- C++ | Constructors | Question 17
- C++ | Constructors | Question 4
- C++ | Constructors | Question 5



