How does TestNG allow you to state dependencies? Explain it with an example.

Dependency is a feature in TestNG that allows a test method to depend on a single or a group of test methods. Method dependency only works if the "depend-on-method" is part of the same class or any of the inherited base classes (i.e. while extending a class). 

@Test(groups={"Car"})
public void drive()
{
}
 
@Test(dependsOnMethods={“drive”}, groups={"Car"})
public void changeGear() 
{
}
 
@Test(dependsOnMethods={“changeGear”}, groups={“Car”})
public void accelerate()
{
}