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

Discussion in 'Java' started by Patel, Oct 22, 2003.

  1. Patel

    Patel Guest

    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.
    Patel, Oct 22, 2003
    #1
    1. Advertising

  2. Patel

    Harald Hein Guest

    "Patel" wrote:

    > 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.
    Harald Hein, Oct 23, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patel
    Replies:
    6
    Views:
    40,478
    Randall R Schulz
    Oct 23, 2003
  2. Replies:
    0
    Views:
    358
  3. Replies:
    2
    Views:
    374
  4. Bruno Desthuilliers
    Replies:
    12
    Views:
    464
    Raymond Hettinger
    Sep 24, 2007
  5. wink
    Replies:
    4
    Views:
    1,162
Loading...

Share This Page