P
Patel
Is it possible to call a Super-class method from the instance of Child-class.
Following conditions:
* Not a Static method
* Method has been overridden in Child Class.
Please see the attached sample code:
public class ClassA
{
public ClassA() { }
void Perform()
{
System.out.print("ClassA");
}
}
public class ClassB extends ClassA
{
public ClassB() { }
public static void main(String[] args)
{
ClassB objB = new ClassB();
ClassA objA = (ClassA) objB;
objA.Perform();
}
void Perform()
{
System.out.print("ClassB");
}
}
Result:
ClassB
Even after the cast the method resolves to the Child Class method.
But I want to access the Parent's method, is there a way ?
Thanks in advance.
Following conditions:
* Not a Static method
* Method has been overridden in Child Class.
Please see the attached sample code:
public class ClassA
{
public ClassA() { }
void Perform()
{
System.out.print("ClassA");
}
}
public class ClassB extends ClassA
{
public ClassB() { }
public static void main(String[] args)
{
ClassB objB = new ClassB();
ClassA objA = (ClassA) objB;
objA.Perform();
}
void Perform()
{
System.out.print("ClassB");
}
}
Result:
ClassB
Even after the cast the method resolves to the Child Class method.
But I want to access the Parent's method, is there a way ?
Thanks in advance.