Calling parent's method even though it has been overridden in the child

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.
 
H

Harald Hein

Patel said:
Is it possible to call a Super-class method from the instance of
Child-class.

Please read a Java textbook. And do all of us a favour. Don't go near
any of the aircraft software your company produces.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,727
Latest member
FelicaTole

Latest Threads

Top