Difference between initializing a class and instantiating an object?

后端 未结 4 1686
鱼传尺愫
鱼传尺愫 2020-11-29 05:46

I tried searching for this question through the search engine but could find a topic that explained the difference between initializing a class and instantiating an object.<

4条回答
  •  被撕碎了的回忆
    2020-11-29 06:11

    Point originOne = new Point(23, 94); -- Example 1

    Rectangle rectOne = new Rectangle(originOne, 100, 200); -- Example 2

    1) Declaration: The code set in bold are all variable declarations that associate a variable name with an object type.

    2) Instantiation: The new keyword is a Java operator that creates the object.

    3) Initialization: The new operator is followed by a call to a constructor, which initializes the new object.

    Reference:https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html#:~:text=Instantiation%3A%20The%20new%20keyword%20is,which%20initializes%20the%20new%20object.

提交回复
热议问题