可以访问,因为无论继承了多少代,父辈的数据和方法都会留给子辈。- package exercise;
- class Grandpa{
- public static String name="GradeFa";
- public static void syso(){
- System.out.println("yo~i'm your GradeFa");
- }
- }
- class Dady extends Grandpa{
- public static int age = 40;
- }
- public class ExtendsTest extends Dady{
- public static void main(String[] args) {
- System.out.println(name);
- System.out.println(age);
- syso();
- }
- }
复制代码 输出:
GradeFa
40
yo~i'm your GradeFa |