📄 cloneablebike.java
字号:
package com.javapatterns.prototype.bike;
public class CloneableBike implements Cloneable // Class we will be cloning
{
private int gears, wheelSize, age; // Local variables
public CloneableBike (int gears, int wheelSize) // Class constructor
{
this.gears = gears;
this.wheelSize = wheelSize;
age = 0;
}
public void setAge(int age) { this.age = age; } // Set the bike age
public int getAge() { return age; }
public int getGears() { return gears; }
public int getWheelSize() { return wheelSize; }
// Method to allow cloning of this class
public Object clone()
{
// Create a new CloneableBike object ready for returning to the caller.
CloneableBike temp = new CloneableBike(gears, wheelSize);
temp.setAge(age);
// Return this new CloneableBike object to the caller, as an Object
// class object
return (Object) temp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -