testng depensonmethods

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.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;

public class TestNG_G_dependsOnMethods {
WebDriver driver;

    @Test
      public void method1() throws Exception{
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        driver.get("http://www.google.com");
          System.out.println("This is first method 1");
          Thread.sleep(3000);
      }
      
      @Test(dependsOnMethods={"method1"})
      public void method2() {
          driver.findElement(By.name("q")).sendKeys("Hello TestNG");
          System.out.println("This is dependsOnMethods method 1");
      }
      

  @BeforeTest
  public void beforeTest() {
      driver = new FirefoxDriver();
      driver.manage().window().maximize();
      
  }

}