Difference between loading a class and instantiating it

后端 未结 5 1421
抹茶落季
抹茶落季 2021-02-08 11:56

Could someone explain what is the difference between Class loading and instantiating a Class. When we load a class with Static variable does it also get instantiated the same ti

5条回答
  •  礼貌的吻别
    2021-02-08 12:55

    Integer.toString(123);
    

    For the above static method call to work, the Integer class must be loaded.

    Integer i = new Integer(123);
    

    And in the above code, I've created an instance (object) of the Integer class (which must also be loaded for this to work, obviously).

    Some classes are not meant to be instantiated (like the Math class, for example, which only has static methods).

提交回复
热议问题