📄 chapter08_01.java
字号:
// ----------------------方法的重载--------------------------
class C_Circle {
private String color;
private double pi=3.14159;
private double radius;
public void setCircle(String str) { // 设置颜色的方法
color=str;
}
public void setCircle(double r) { // 设置半径的方法
radius=r;
}
public void setCircle(String str,double r) { // 设置半径与颜色的方法
color=str;
radius=r;
}
public void show() { // 输出圆的半径与颜色
System.out.println("color="+color+", Radius="+radius);
System.out.println("area="+pi*radius*radius);
}
}
public class Chapter08_01 {
public static void main(String[] args) {
C_Circle cir=new C_Circle();
cir.setCircle("RED"); // 调用设置圆颜色的方法------注意------必须通过声明对象才能调用其他类里的方法
cir.setCircle(8.0); // 调用设置圆颜色的方法------注意------必须通过声明对象才能调用其他类里的方法
cir.show(); // 调用设置圆颜色的方法------注意------必须通过声明对象才能调用其他类里的方法
cir.setCircle("BLUE",7.5); // 调用设置圆颜色的方法------注意------必须通过声明对象才能调用其他类里的方法
cir.show(); // 调用设置圆颜色的方法------注意------必须通过声明对象才能调用其他类里的方法
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -