class Base{
public void method(){
System.out.println("Base 1 Method");
}
public void BaseMethod()
{
System.out.println("BaseBMethod Method");
}
}
class Derived1 extends Base{
public void method(){
System.out.println("Derived 1 Method");
}
public void Derived1Method()
{
System.out.println("Derived1 Method");
}
}
class Derived2 extends Base{
public void method(){
System.out.println("Derived2 Method");
}
public void Derived2Method()
{
System.out.println("Derived2 Method");
}
}
public class ClassTest
{
static public void main(
String [] args)
{
Base b = new Derived1 ();
Derived1 d1 = new Derived1();
Derived2 d2 = new Derived2();
b = d1; b.method();
d1 = (Derived1) b; d1.method();
b.BaseMethod();
//b.Derived1Method(); // Will give error
}
}
1)In this example what b=d1 does can any body answer me please. I'm getting confused which reference assign to which reference
2) d1 = (Derived1) b; How this object is type casted, I mean to which class.
Thnaks,
Kanthu