[求助]关于上转型对象的问题。
代码如下:
package File;
class 类人猿{
char m='T';
void crySpeck(String s){
System.out.println(s);
}
}
class People extends 类人猿{
char m='A';
double n=60;
void computer(int a,int b){
int c=a+b;
System.out.println(a+"加"+b+"等于"+c);
}
void crySpeck(String s){
System.out.println(m+"**"+s+"**"+m);
}
}
public class File_5_101 {
public static void main(String args[]) {
People wang=new People();
类人猿 monkey=wang;
monkey.crySpeck("I Love This Game!!");
System.out.println(monkey.m);/*这里为什么不是A呢?是只能操作隐藏成员变量吗?*/
People zhang=(People) monkey;
zhang.computer(55, 33);
zhang.m='W';
System.out.println(zhang.m);
}
我有些疑问。
上转型对象操作重复的成员变量时,是在父类中操作,上转型对象操作的如果是隐藏方法,那就必须在子类中操作,是吗?