class A{
protected int a
protected int b
public A(int a, int b){
this.a = a
this.b = b
}
}
class B extends A{
protected int c
//此入必须改动,否则是一种面向对象方面的错误
public B(int a, int b, int c) {
super(a, b)
this.c = c
}
public int add(){
return a + b + c
}
}
public class Exam02 {
public static void main(String[] args) {
B e1 = new B(3, 4, 5)
System.out.println(e1.add())
}
}
运行测试:
12
publicclass
Employee
:
Person
{
private
string
name
//姓名
private
string
idcode
//身份z
private
string
address
//住址
private
string
department//部门
public
Employee()
{
}
public
string
Name
{
get
{
return
name
}
set
{
name
=
value
}
}
public
string
IDCode
{
get
{
return
idcode
}
set
{
idcode
=
value
}
}
public
string
Address
{
get
{
return
address
}
set
{
address
=
value
}
}
public
string
Department
{
get
{
return
department
}
set
{
department
=
value
}
}
}
这样可以通过
Employee
Employee=new
Employee()
Employee.Name
Employee.IDCode
Employee.Address
Employee.Department
直接获取值即可,同样Manager也可以这样做。不需要在设计方法来获取了!
可以通过Employee.Name="张三"这样来赋值。
如果不是读取数据库或其他文件的话,设计一个方法来获取值不如这样简单实用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)