高级方法访问与异常处理
1. 方法重载与构造函数
1.1 构造函数示例
在面向对象编程中,构造函数是用于初始化对象的特殊方法。以下是一个 Circle 类的示例,展示了多个不同参数的构造函数:
public class Circle
{
private int x;
private int y;
private int radius;
public Circle()
{
x = 0;
y = 0;
radius = 0;
}
public Circle(int r)
{
x = 0;
y = 0;
radius = r;
}
public Circle(int new_x, int new_y)
{
x = new_x;
y = new_y;
radius = 0;
}
public Circle(int new_x, int new_y, int r)
{
x = new_x;
y = new_y;
radius = r;
}
public void print_circle_info()
{
Console.WriteLine("Circle: Center = ({0},{1})", x, y);
Console.W
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



