java面向对象、继承、抽象
class Student {
private String name;
private int age;
public static String city;
Student() {
}
Student(int a) {
age = a;
}
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
private int getAge() {
return age;
}
public void setCity(String c) {
city = c;
}
public String getCity() {
return city;
}
}
在考虑面向对象的特性时,程序中清楚显示了哪些特性
我如何知道上述代码是:
- 抽象
- 封装
- 数据隐藏
- 继承权
- 多态性
# 1 楼答案
抽象-没有(代码中没有任何抽象成员或类)
封装——是(将代码和数据绑定在一起——类本身)
多态性-否(没有同名的多个函数)
继承-否(没有继承这个类的类,反之亦然)