[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 618
  • Last Modified:

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?
0
KaranGupta
Asked:
KaranGupta
  • 2
1 Solution
 
CPColinCommented:
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
 
CPColinCommented:
Yes.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now