class One
{
void show1()
{
System.out.println("super class");
}
}
class Two extends One
{
static void show2()
{
System.out.println("subclass");
}
}
public class Cast
{
public static void main(String[] args)
{
One o=(One) new Two();
o.show1();
}
}
How does this statement work in this code One o=(One) new Two();
? Why can't I use like this
Two o=(One) new Two();
? I am confused of using casting, though o here is super class variable.. Why can't I refer sub class method using o?