Thursday, January 31, 2019

Copy Constructor example

package com.concretepage;
public 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;
    }
    @Override
    public String toString() {
    return "(" + re + " + " + im + "i)";
    } 
}

No comments:

Post a Comment