package com.wwj.myproject;
public class Perple {
String name;
int id = 1001;
}
public class Student extends Perple{
int id = 2023;
String code;
public void showCode(){
System.out.println("我的学号:"+id);
}
public void showMyId(){
System.out.println("我的证件号:"+super.id);
}
public static void main(String[] args) {
Student stu = new Student();
stu.showCode();
stu.showMyId();
}
}
输出结果:
我的学号:2023
我的证件号:1001
子类的属性不会被父类覆盖
最新推荐文章于 2024-05-21 22:13:42 发布