Java examples for Object Oriented Design:To String
Reimplementing toString() Method of the Object Class in the SmartIntHolder Class
class MyClass {//from ww w . j av a 2 s .com private int value; public MyClass(int value) { this.value = value; } public void setValue(int value) { this.value = value; } public int getValue() { return value; } // Re-implement toString() method of the Object class public String toString() { // Return the stored value as a string String str = String.valueOf(this.value); return str; } }