你的要求可以 :
//构造函数
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++中这些权限是跟继承有关的。
你现在懵是因为没有真正理解什么是继承,什么是私有,这是一种概念的体会,不是概念的使用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)