C#高手进!关于属性字段赋值的!

C#高手进!关于属性字段赋值的!,第1张

你应该研究下构造函数。

你的要求可以 :

//构造函数

public Program(int a,int b,int c)

{

//赋值

xx=a

yy=b

zz=c

}

然后使用的时候就 program p=new program(x1,x2,x3)

就把x1,x2,x3传进去了,你再使用p.method()调用方法,就能得出结果。

希望回答对你有用。

abstract class shape {

abstract double getCircumference()

}

class triangle extends shape {

private int a

private int b

private int c

triangle(int a, int b, int c) {

this.a = a

this.b = b

this.c = c

}

double getCircumference() {

if (a <= 0 | b <= 0 | c <= 0 | a + b <= c | b + c <= a | a + c <= b) {

return 0

}

return a + b + c

}

}

class square extends shape {

private int a

private int b

square(int a, int b) {

this.a = a

this.b = b

}

double getCircumference() {

if (a <= 0 | b <= 0) {

return 0

}

return (a + b) * 2.0

}

}

继承是一定全继承的,也就是说子类一定包含父类.

私有公有释访问权的问题,根是不是继承没关系,私有的意思是只能在本类内使用,公共类是可以外部访问的.

C++中也是有的,而且还有一个友类,在C++中这些权限是跟继承有关的。

你现在懵是因为没有真正理解什么是继承,什么是私有,这是一种概念的体会,不是概念的使用。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11893275.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存