> hi.I am doing exercise c-2.5 of java data structure book. but I have a problem.question : write a program that consist of three classes, A, B, C, such that B extends A and C extends B. Each class should define an instance variable named "x". Describe a way for a method in C to access and set A's version of x to a given value, without changing B or C's version.I wrote these three classes but in method setX() there is errors.please guide me ...public class A {public int x;public A(){x=0;}}public class B extends A{private int x;public B(){x=0;}}public class C extends B{public int x;public C(){x=0;}public void setX(int a){super.x=a;}} 解决方案 这篇关于访问父类变量的父类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 07:26