0

In this main class why cant i reassign the object value,as seen in the code

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

//main class
public class CollectionClass {

    //using a Map Collection
    Map<String, String> map = new HashMap<String, String>();
    //re-assigning the object reference to LinkedHashMap
    map = new LinkedHashMap<String, String>(); //<- getting error

    public static void main(String... args) {

        map = new LinkedHashMap<String, String>(); //<-- error if not static
    }
}
denvercoder9
  • 2,979
  • 3
  • 28
  • 41

0 Answers0