Overriding method

Posted on 2012-09-21
Last Modified: 2012-09-22

In Java I have written the code

class BaseClass
	public void Display()
		System.out.println("This is the method of base class");

class ChildClass extends BaseClass
	public void Display()
		System.out.println("This is the method of child class");

class MainClass
	public static void main(String args[])
		ChildClass c = new ChildClass();

Open in new window

Here I have declared method Display() in the ChildClass class. Is this the way we can override a method. Aren't we using any keyword like override for overriding the method?
Question by:KaranGupta
    LVL 14

    Accepted Solution

    Java requires no special keyword in order to override a method. Java 1.6 and above does have the @Override annotation, but it's not required.

    Author Comment

    So the code I have written is an example of method overriding?
    LVL 14

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now