I want to access the parent's member function from the child's reference variable.
My code :
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();
}
}
The output is :
in Child class
in Child class
which means both times the child's member function is being called. What would be the way to sort this out?