Wednesday, August 29, 2018

What's the Difference Between Java and C++ Constructors?

If you are a C++ programmer who is now learning Java, you will find a lot of similarities between these two popular object-oriented programming languages. Both of these languages support abstraction, encapsulation, class, object, and other OOP concepts. But, there are some subtle differences as well. Both Java and C++ have a constructor, and they work the same way in Java as they do in C++. But, the way they are called is different.

For example, in Java, a constructor must be called by using the  new() operator. There is no other way to explicitly call the constructor while creating an object, but in C++, you can do it without a new operator. This is also a good interview question for programmers who know both Java and C++.



from DZone.com Feed https://ift.tt/2wBVvCj

No comments:

Post a Comment