TestNG Dependency test method

package seleniumTestNG;

import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;

public class TestNG_G_dependsOnMethods {
    WebDriver driver;

    public void method1() {
        System.out.println("This is method 1");

    public void method2() throws Exception{
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        System.out.println("This is method 2");

    public void beforeTest() {
        driver = new FirefoxDriver();
        // System.setProperty("webdriver.chrome.driver","D:\\lib\\chromedriver.exe"); //---> Chromedriver path
        // driver = new ChromeDriver();



What is dependency Test?

Dependency is a feature in TestNG that allows a test method to depend on a single or a group of test methods.
This will help in executing a set of tests to be executed before a test method.

How it can be done in testNG?

TestNG allows you to specify dependencies either with: 
Using attribute dependsOnMethods in @Test annotations
Using attribute dependsOnGroups in @Test annotations.