override display method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poopsy
    New Member
    • Nov 2006
    • 50

    #1

    override display method

    hi all
    suppose im implemeting a class emplyee where i have a method to display details
    Code:
    public void display(){
    System.out.printtln("The name is" + name);
    etc..
    }
    now i hav a subclass that inherits from the above class and i want to override the display method
    how to i call that
    Code:
    public void display(){
    super.display( ); //is that right????
    System.out.println("The...);
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Yep, that's correct (you could've just compiled and run your code and see for
    yourself). The display() method in the derived class first calls the display method
    in the super class and then does what it has to do.

    kind regards,

    Jos

    Comment

    Working...