Hey @sradha, yes there is a way by which you can do exactly what you want. This is known as dependency in testNG.
Dependency is when you have a function which needs to run after a particular function/s completes testing. By this you can do exactly same as you require.
All you need to do is you need to make a test function dependent.
@Test (dependsOnMethods= "h2" )
public void h1()
{
System.out.println("test case 1");
}
@Test
public void h2()
{
System.out.println("test case 2");
}
@Test
public void h3()
{
System.out.println("test case 3");
}
@Test
public void h4()
{
System.out.println("test case 4");
}
This way h1 will run only when h2 is completed.
Hope this helps.