Overriding method

Hi

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();
		c.Display();
	}
}

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?
KaranGuptaAsked:
Who is Participating?
 
CPColinSenior Java ArchitectCommented:
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.
0
 
KaranGuptaAuthor Commented:
So the code I have written is an example of method overriding?
0
 
CPColinSenior Java ArchitectCommented:
Yes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.