作为示例,我想模仿String对象的功能:
String mystring = new String ( "Hi there." );
System.out.println(mystring); // prints "Hi there." without calling any methods on String
// (that is what I want with my object)
System.out.println(mystring.toUpperCase()); // prints "HI THERE."
Run Code Online (Sandbox Code Playgroud)
从这开始:
class MyObject
{
private Int value ;
public MyObject ( Int value )
{
this.value = value ;
}
public Int getValue ( )
{
return this.value ;
}
public Int multiplyBy ( Int multiplier )
{
return this.value * multiplier ;
}
} …Run Code Online (Sandbox Code Playgroud) java ×1