63 797
Assignments Done
99,4%
Successfully Done
In August 2018

Answer to Question #57481 in Java | JSP | JSF for Nancy Rodriguez

Question #57481
How do you override a method from another class?
Expert's answer
In Java, when a subclass contains a method that overrides a method of the superclass. Example:
class A {
public void message() {
System.out.println("Hi");
}
}

public class B extends A {
@Override
public void message() {
System.out.println("Hello");
}
}
Class A represents the superclass and implements a method call message(). The subclass called B inherits every method that could be in the A class. However, class B overrides the method message(), replacing its functionality from A.

A parking = new A();
parking.message(); // Prints "Hi"

A dates = new B(); // Polymorphism
dates.message(); // Prints "Hello"

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions