#include <iostream>
class Joe { private: int val; public: Joe(int v = 0) { val = v; } void set(int v) { val = v; } int get() { return val; } }; int main(int argc, char **argv) { Joe j1(1), j2, j3; j2 = j1; j3 = j1; j1.set(10); j2.set(20); j3.set(30); std::cout << "j1: " << j1.get() << ", j2: " << j2.get() << ", j3: " << j3.get() << std::endl; } | class Joe {
private int val; public Joe() { val = 0; } public Joe(int v) { val = v; } public void set(int v) { val = v; } public int get() { return val; } } class Corr { public static void main(String[] argv) { Joe j1 = new Joe(1), j2, j3; j2 = j1; j3 = j1; j1.set(10); j2.set(20); j3.set(30); System.out.println("j1: " + j1.get() + ", j2: " + j2.get() + ", j3: " + j3.get()); } } |
Output: j1: 10, j2: 20, j3: 30 | Output: j1: 30, j2: 30, j3: 30 |