Link to home
Start Free TrialLog in
Avatar of KaranGupta
KaranGupta

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of CPColin
CPColin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KaranGupta
KaranGupta

ASKER

So the code I have written is an example of method overriding?
Yes.