I'm a beginner in Java and I was playing with some Java code. However I couldn't sort out why is it giving runtime error when I assign the reference of a parent class object to a child class variable. I've done explicit typecasting too. Is there any way possible to resolve it?
class Employee{
int e;//creating empty class
}
class Teacher extends Employee{
int f;//creating empty class
}
class run{
public static void main(String args[]){
Employee e;
e= new Employee();
Teacher t;
t= (Teacher)e; //giving runtime error
}
}