我想从子引用变量访问父类的成员函数。使用函数覆盖时如何访问父类的函数
我的代码:
class Emp
{
static String Cname="Google";
int salary ;
String Name;
void get(String s1,int s2)
{
Name=s1;
salary=s2;
}
void show()
{
System.out.println(Name);
System.out.println(salary);
System.out.println(Cname);
}
}
public class Practice extends Emp{
/**
* @param args
*/
void show()
{
System.out.println("in Child class");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Practice e=new Practice();
e.show();
e.get("Ratan",200000);
((Emp)e).show();
}
}
输出是:
in Child class
in Child class
这意味着两次孩子的成员函数被调用。有什么办法来解决这个问题?
谢谢我得到了它。 –