Reimplementing toString() Method of the Object Class in the SmartIntHolder Class - Java Object Oriented Design

Java examples for Object Oriented Design:To String

Description

Reimplementing toString() Method of the Object Class in the SmartIntHolder Class

Demo Code

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;
    }
}

Related Tutorials