Hi Sara,
U can certainly do that. But take care of following situation.
class Base
{
Base()
{
disp();
}
public void disp()
{
System.out.println("in disp of Base");
}
}
class Derived extends Base
{
Derived()
{
}
public void disp()
{
System.out.println("in disp of Derived");
}
}
class OverrideDemo
{
public static void main(
String[] args)
{
Base b1 = new Base(); // case 1 : Base class disp called
Base b2 = new Derived(); // case 2: Derived class disp called
}
};
If there is a call to a method from constructor in Base class & if u create an object of type Base, it works fine as in case 1. But if you derive a class from such a base class & you override that method in the derived class. The derived class method will be called from Base class constructor.
Warm Regards,
meghana