TOKYO, July 3 (Reuters) - Japan's Nikkei share average rose for a fourth consecutive day on Wednesday, as heavyweight technology stocks tracked overnight gains in U.S. megacap growth stocks.

The Nikkei gained 1.26% to close at 40,580.76.

The broader Topix also rose for a fourth straight day, closing up 0.54% at 2,872.18.

Wall Street's main stock indexes closed higher on Tuesday, boosted by gains in Tesla and megacap growth stocks, but volumes were thin ahead of the July 4 holiday and the closely watched release of June nonfarm payrolls on Friday.

"Investors rotated their targets today. They sold outperforming shares to take profits and bought cheaper stocks," said Naoki Fujiwara, senior fund manager at Shinkin Asset Management.

"The Nikkei tracked Wall Street, higher but also those who were late in catching up to the recent rally bought Nikkei futures, which lifted the main index," said Fujiwara.

Topix's growth stock index, which lags behind the value share index for its weekly performance, jumped 0.93%, while the value share index edged up 0.18%

Chip-making equipment maker Tokyo Electron rose 2.6% to provide the biggest boost to the Nikkei. Chip-testing equipment maker Advantest gained 2.38%.

Electronic components maker TDK jumped 5.24% and silicon wafer maker Shin-Etsu Chemical climbed 2.22%.

Meanwhile, Hitachi slipped 1.58% to weigh on the Topix the most. Insurer Tokio Marine Holdings dropped 1.18%. Toyota Motor fell 0.24%.

Of the more than 1,600 stocks trading on the Tokyo Stock Exchange's (TSE) prime market, 59% of the shares rose, while 37% fell and 2% were unchanged.

The machinery sector rose 2.2% and was the top performer among the TSE's 33 industry sub-indexes. (Reporting by Junko Fujita; Editing by Sonia Cheema and Varun H K)