What is the main difference in object creation between Java and C++?

后端 未结 7 553
感动是毒
感动是毒 2021-01-31 19:12

I\'m preparing for an exam in Java and one of the questions which was on a previous exam was:\"What is the main difference in object creation between Java and C++?\"

I t

相关标签:
7条回答
  • 2021-01-31 20:13

    What is the main difference in object creation between Java and C++?

    Unlike Java, in C++ objects can also be created on the stack.

    For example in C++ you can write

    Class obj; //object created on the stack
    

    In Java you can write

    Class obj; //obj is just a reference(not an object)
    obj = new Class();// obj refers to the object
    
    0 讨论(0)
提交回复
热议问题